Illuminate\Contracts\Container\BindingResolutionException Target class [UserController] does not exist.
Hi Guys,
I'm new to Laravel. I started working on Laravel 7 a week ago, built an API and everything is working fine. I attempted to recreate the same API with Laravel 8 but my api routes don't seem to be working anymore. I get an error that says:
"Illuminate\Contracts\Container\BindingResolutionException
Target class [UserController] does not exist."
I have defined api routes like so: Route::resource('users', 'UserController', ['except' => ['create', 'edit']]);
Came here with the same issue looking for the solution. Thank you for answering this. Is this documented anywhere? Couldn't find in the Docs. IDK... Seems like a small step backwards to me. ĀÆ\(ć)/ĀÆ
I am very new to laravel and learning it. Very interesting to learn. Started with 7 and now working on 8. I came here with the same error as stated. Followed the syntax as stated and it's resolved.
This usually happens because you're using a different Controller Namespace in your class. In case you are not familiar with namespaces, I highly recommend reading more about it and get familiar with it. Composer 2 improve the PSR-4 autoloading standard and understand how to use it can avoid future issues.
Laravel includes a Namespace option on Route::groups to allows you to call the new namespace. With this, you avoid miss use of importation on your routes files and improve the readability of your code. This is how you can implement your need:
Imaging your new class is in app/Http/Controllers/Users/ folder and namespace, you can call this controller with the following route:
@ricardov For Laravel 7 that is the way to stop "Illuminate\Contracts\Container\BindingResolutionException Target class [......Controller] does not exist.". Commenting out protected $namespace = 'App\Http\Controllers' property in RouteServiceProvider will also do the trick. Lastly is to remove namespace($this->namespace) in boot method.
public function boot()
{
$this->configureRateLimiting();