0

The following errors occurs in my laravel 8 application:

Illuminate\Contracts\Container\BindingResolutionException .Target class [MarketsouhaibController] does not exist. laravel 8

The following stracktrace is shown:

try {
  $reflector = new ReflectionClass($concrete);
} catch (ReflectionException $e) {
  throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
}

in tutorial video it work but with my laravel 8 does not work ....

MaartenDev
  • 5,631
  • 5
  • 21
  • 33
  • Does this answer your question? [Target class does not exist. problem in laravel 8](https://stackoverflow.com/questions/63882034/target-class-does-not-exist-problem-in-laravel-8) – Kamlesh Paul Apr 19 '21 at 11:34
  • Could you add your api.php/web.php files? – MaartenDev Apr 19 '21 at 12:26
  • Does this answer your question? [Target class controller does not exist - Laravel 8](https://stackoverflow.com/questions/63807930/target-class-controller-does-not-exist-laravel-8) – I. Antonov Jun 07 '21 at 04:54

3 Answers3

3

From the lack of details I am guessing you are using the original controller routing syntax Route::get('/', 'MarketsouhaibController@index'), the syntax we all have been using for a long time, and this is a common issue. This syntax worked till Laravel 7. From 8 they changed it.

From Laravel 8, a new syntax is introduced and is the new standard. You have two options now. You either use the String Syntax or PHP callable syntax as shown below.

//string syntax
Route::get('/', 'App\Http\Controllers\MarketsouhaibController@index')
//php callable syntax
use App\Http\Controllers\MarketsouhaibController; //must be placed at the top of routes

Route::get('/', [MarketsouhaibController::class, 'index']);

But if you still want to use the original auto-prefixed controller routing just follow the following steps.

  1. Navigate to your RouteServiceProvider
  2. Add protected $namespace = 'App\Http\Controllers';

A personal suggestion, before starting please read the documentations. There are there for a reason. The solution I posted is also available in the Documentation provided by Laravel and the Upgrade Guide they posted.

I. Antonov
  • 625
  • 2
  • 14
  • 33
1

you can see carefully namespace in controller and route, must be same, it solve for me

0

run this:

composer dump-autoload