Are you sure that's the file giving the error?
Target class [Modules\User\Http\Controllers\Modules\User\Http\Controllers\UserController] does not exist.
I installed modules when I create a User module I write in web.php
use Illuminate\Support\Facades\Route;
use Modules\User\Http\Controllers\UserController;
Route::resource('users', UserController::class);
I see this error
Target class [Modules\User\Http\Controllers\Modules\User\Http\Controllers\UserController] does not exist.
What do you mean? "error"
@irankhosravi the code shown should work. So I am asking if the error might be coming from another file. Like inside UserController perhaps?
<?php
namespace Modules\User\Http\Controllers;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\User\Entities\User;
class UserController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index()
{
$users = User::query();
if($keyword = request('search')) {
$users->where('first_name', 'LIKE', "%{$keyword}%")
->orWhere('last_name', 'LIKE', "%{$keyword}%");
}
if(request('admin')) {
$users->where('level' , 'admin');
}
$users = $users->latest()->paginate(25);
return view('user::admin.index', compact('users'));
}
Hello just use optimize:clear and optimize route:clear and route:cache
@krackjack I run this in cmd , but my problem did not solve yet
@irankhosravi Can you share screen shot?
@krackjack What screenshot?
@irankhosravi Your error in browser
@irankhosravi just remove the protected $namespace as already suggested and the error will be fixed
@irankhosravi comment this and try
protected $namespace = '\Modules\User\Http\Controllers';
Are you sure you have the Controller in Modules folder? @irankhosravi
Do you have namespace set it in the RouteServiceProvider? If so remove it
@irankhosravi I can see below that I was right. Remove that namespace and it should work
Do you have a default namespace defined in the RouteServiceProvider, e.g.
// app/Providers/RouteServiceProvider.php
protected $namespace = '\Modules\User\Http\Controllers';
<?php
namespace Modules\User\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* The module namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $namespace = 'Modules\User\Http\Controllers';
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @return void
*/
public function boot()
{
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(module_path('User', '/Routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(module_path('User', '/Routes/api.php'));
}
}
Remove this:
protected $namespace = 'Modules\User\Http\Controllers';
(unless every Controller is under that namespace in your application)
What is this Modules package anyway - something third-party or your own???
@tykus What do you mean? Remove this
@irankhosravi I mean delete the line protected $namespace = 'Modules\User\Http\Controllers'; from the RouteServiceProvider class.
restart the server
php artisan cache:clear; php artisan optimize
@limewater23 Why are you resurrecting an old thread that already has the correct solution, only to suggest something that wouldn’t do any good at all?
@kokoshneta it's a supplement, I tried your correct solution, but it didn't work for me, and it took a while and I figured out and typed here if only people have a similar experience.
just to like this
Route::group(['namespace'=>'Tavakolian\User\Http\Controllers'], function(){ Auth::routes(); Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home'); });
change the namespace with your own namespace i mean change the 'Tavakolian\User\Http\Controllers' with your own
Please or to participate in this conversation.

