Answer the question
In order to leave comments, you need to log in
Laravel. How to fix error when using controller "Class does not exist"?
You need to build a site on Laravel with a modular system. I found a guide, made a "base" as written, in order to calmly study the material. It didn't work out.
In general, I created a folder at the root with the following structure:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ModulesServiceProvider extends ServiceProvider {
public function boot() {
$modules = config("modules.modules");
if ($modules) {
foreach($modules as $module) {
// Routes
if (file_exists(__DIR__.'/../../Modules/'.$module.'/Routes/routes.php')) {
$this->loadRoutesFrom(__DIR__.'/../../Modules/'.$module.'/Routes/routes.php');
}
// Views
if (is_dir(__DIR__.'/../../Modules/'.$module.'/Views')) {
$this->loadViewsFrom(__DIR__.'/../../Modules/'.$module.'/Views', $module);
}
// Migration
if (is_dir(__DIR__.'/../../Modules/'.$module.'/Migration')) {
$this->loadMigrationsFrom(__DIR__.'/../../Modules/'.$module.'/Migration');
}
// Lang
if (is_dir(__DIR__.'/../../Modules/'.$module.'/Lang')) {
$this->loadTranslationsFrom(__DIR__.'/../../Modules/'.$module.'/Lang', $module);
}
}
}
}
}
'providers' => [
...,
App\Providers\ModulesServiceProvider::class,
...
];
return [
'modules' => [
'Test',
]
];
namespace Modules\Test\Controllers;
use Illuminate\Routing\Controller;
class TestController extends Controller {
public function index() {
return view('Test::index');
}
}
Route::namespace('Modules\Test\Controllers')->get('/', '[email protected]');
Route::group(['namespace' => 'Modules\Test\Controllers'], function(){
Route::get('/', '[email protected]');
});
Answer the question
In order to leave comments, you need to log in
composer.json:
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
},
},
Route::namespace('\Modules\Test\Controllers') ? Is he at the root?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question