Route resource not working in Laravel 8.x
Solution 1
Finally, I found out the answer in laravel 8.x upgarade guide. I have texted the controller name with full namespace, instead of importing it.
Route::prefix('admin')->namespace('Admin')->group(static function() {
Route::middleware('auth')->group(static function () {
//...
Route::resource('profile', '\App\Http\Controllers\Admin\ProfileController');
});
});
Solution 2
Run following step for clear route cache
php artisan route:clear
Solution 3
Route::resource('invoice','\App\Http\Controllers\InvoiceController');
Solution 4
Make sure you followed the upgrade guide. There have been quite a few things that changed from v7 to v8.
To App/Providers/RouteServiceProvider.php
add $namespace
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
}
You also find more answers here: https://stackoverflow.com/a/63808132/799176
Solution 5
I also faced same issue with Laravel 7 latest version. See how I solved it:
First include this directory on the page
enter image description here
use \App\Http\Controllers\Admin\ProfileController
Then call the full version of the route including the className like this
Route::resource('profile', '\App\Http\Controllers\Admin\ProfileController');
This will automatically create different routes for all methods defined in the ProfileController class. See an example in the image attached using TodoController.
Alisher Nasrullayev
Updated on June 13, 2022Comments
-
Alisher Nasrullayev almost 2 years
I have a problem with the
Route::resource()
method in Laravel 8.x. The error it returns is:Target class [Admin\App\Http\Controllers\Admin\ProfileController] does not exist.
Here is my code in routes/web.php:
Route::prefix('admin')->namespace('Admin')->group(static function() { Route::middleware('auth')->group(static function () { //... Route::resource('profile', ProfileController::class); }); });
I could not find where the problem is.
-
Alisher Nasrullayev over 3 yearsI have imported the class
-
Muhammad Rizwan Munawar over 3 yearssure, your got solution or not
-
gvd over 2 yearsNote that when this could works, the solution given in upgrade 8.x guide in routing section laravel.com/docs/8.x/upgrade#routing is set to null $namespace property in RouteServiceProvider like is suggested bellow stackoverflow.com/questions/63845754/…