3

I have cloned project from github and installed in my local system everything is working fine.

And i created controller through command, the controller is created but when i try to use controller function the error shows me like below.

BindingResolutionException

Target [App\Http\Controllers\SomeController] is not instantiable. in Container.php (line 895)

I tried to solve this problem by running command below:

php artisan cache:clear

php artisan clear-compiled

composer dump-autoload

php artisan optimize

php artisan config:clear

But i still got same error. Kindly help me to resolve this issue.

My controller is:

<?php

 namespace App\Http\Controllers;

 use Illuminate\Http\Request;

 class SomeController extends Controller
 {
  public function getIndex() {
    echo "string";
  }
 }

AppServiceProvider.php :

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{
/**
 * Bootstrap any application services.
 *
 * @return void
 */
 public function boot()
 {
    //
    Schema::defaultStringLength(191);
 }

  /**
   * Register any application services.
   *
   * @return void
  */
  public function register()
  {
      //
  }
}

Controller.php

<?php

 namespace App\Http\Controllers;

 use Illuminate\Foundation\Bus\DispatchesJobs;
 use Illuminate\Routing\Controller as BaseController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
 use Carbon\Carbon;

class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;


protected function __construct() {

   $variable2 = "I am Data 2";
   View::share ( 'variable2', $variable2 );
} 

protected function create_permission($role_type_id,$module_id)
{
    $CheckCreatePermission = \DB::table('role_type_access')->where(['role_type_id'=> $role_type_id,'module_id'=>$module_id])->select('create')->get();
    if(!empty($CheckCreatePermission[0]))
    {
        if($CheckCreatePermission[0]->create===1)
        {
            return 1;
        }
        return 0;
    }
    return 0;
}

protected function edit_permission($role_type_id,$module_id)
{
    $CheckEditPermission = \DB::table('role_type_access')->where(['role_type_id'=> $role_type_id,'module_id'=>$module_id])->select('edit')->get();
    if(!empty($CheckEditPermission[0]))
    {
        if($CheckEditPermission[0]->edit===1)
        {
            return 1;
        }
        return 0;
    }
    return 0;
}

protected function delete_permission($role_type_id,$module_id)
{
    $CheckDeletePermission = \DB::table('role_type_access')->where(['role_type_id'=> $role_type_id,'module_id'=>$module_id])->select('delete')->get();
    if(!empty($CheckDeletePermission[0]))
    {
        if($CheckDeletePermission[0]->delete===1)
        {
            return 1;
        }
        return 0;
    }
    return 0;
}

protected function view_permission($role_type_id,$module_id)
{
    $CheckViewPermission = \DB::table('role_type_access')->where(['role_type_id'=> $role_type_id,'module_id'=>$module_id])->select('view')->get();
    if(!empty($CheckViewPermission[0]))
    {
        if($CheckViewPermission[0]->view===1)
        {
            return 1;
        }
        return 0;
    }
    return 0;
}

protected function view_all_permission($role_type_id,$module_id)
{
    $CheckLayoutPermission = \DB::table('role_type_access')
    ->join('modules', 'role_type_access.module_id', '=', 'modules.id')
    ->where(['role_type_access.role_type_id'=> $role_type_id,'role_type_access.view'=>1,'role_type_access.module_id'=>$module_id])
    ->select('role_type_access.module_id','role_type_access.view','role_type_access.create','role_type_access.edit','role_type_access.delete','modules.name','modules.label')->get();

    return $CheckLayoutPermission;

   // print_R($$CheckViewMenuPermission);
   // echo count($CheckViewMenuPermission);
   /*        if(!empty($CheckViewPermission[0]))
    {
        if($CheckViewPermission[0]->view===1)
        {
            return 1;
        }
        return 0;
    }
    return 0;*/
}

public function getDownload($file_path,$file_name)
{
    //PDF file is stored under project/public/download/info.pdf
    $file= public_path().'/uploads/'.$file_path.'/'.$file_name;
    $headers = array(
              'Content-Type: application/pdf',
            );

    return \Response::download($file, $file_name, $headers);
}

public function updateTracker($tracked_date,$action)
{

    $Globaltracks = \DB::table('global_tracks')->where('tracked_date', $tracked_date)->get();
    if (count($Globaltracks) > 0) {

        \DB::table('global_tracks')
        ->where('tracked_date', $tracked_date)
        ->increment($action,1,['updated_at'=>Carbon::now()->toDateTimeString()]);

    } else {

        $Globaltracks_id = \DB::table('global_tracks')->insert(
        ['tracked_date' => $tracked_date,$action => 1,'created_at'=>Carbon::now()->toDateTimeString()]);

    }

   }


   }
3
  • Provide your AppServiceProvider.php code to check the binding way that your code followed Commented Aug 17, 2017 at 5:44
  • Have updated my question with appserviceprovider @AddWebSolutionPvtLtd Commented Aug 17, 2017 at 5:47
  • Try by making constructor of your parent controller as public instead of Protected Commented Aug 17, 2017 at 9:21

2 Answers 2

5

Change Your Constructor Access Modifier to Public. It solved my problem.

public function __construct() {

   $variable2 = "I am Data 2";
   View::share ( 'variable2', $variable2 );
} 

Sign up to request clarification or add additional context in comments.

Comments

0

Update your SomeController with the below code:

<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class SomeController extends Controller
{
    public function getIndex() {
        echo "string";
    }
}

3 Comments

@V.php: Which laravel version you are using?
Im using laravel 5.4
Requested about SomeController where you facing the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.