Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route resource not working in Laravel 8.x

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.

enter image description here

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.

like image 897
Alisher Nasrullayev Avatar asked Nov 29 '22 12:11

Alisher Nasrullayev


2 Answers

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');
    });
});
like image 136
Alisher Nasrullayev Avatar answered Dec 04 '22 03:12

Alisher Nasrullayev


Run following step for clear route cache

php artisan route:clear
like image 43
arash narimani Avatar answered Dec 04 '22 03:12

arash narimani