PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, April 19, 2022

[FIXED] Why there is an error with the resource controller?

 April 19, 2022     laravel     No comments   

Issue

I have an Admin folder with UserController (resource) inside

--Controllers
    --Admin
      -- UserController.php

In web.php I have the following routes:

use App\Http\Controllers\Admin\UserController;


    Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function (){
            Route::get('/', [HomeController::class, 'index']);
            Route::resource('user', UserController::class);
   });

UserController

namespace App\Http\Controllers\Admin;

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

class UserController extends Controller
{ 
    public function index()
    {
       return view('admin.user.index');
    }
}

When I try to go to admin/user I get an error

Target class [Admin\App\Http\Controllers\Admin\UserController] does not exist.

I will be grateful for the hint.


Solution

You set the namespace to Admin so it adds it in the base namespace. Just remove the namespace. It should work.

Route::group(['prefix' => 'admin'], function (){
            Route::get('/', [HomeController::class, 'index']);
            Route::resource('user', UserController::class);
});


Answered By - Karl Mounguengui
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing