Answer the question
In order to leave comments, you need to log in
How to set "/" route in Laravel module?
Hello.
There are module routes in modules.php:
<?php
Route::group(['namespace' => 'Gepard\Modules\Core\Controllers', 'middleware' => 'admin'], base_path('app/Modules/Core/Routes/routes.php'));
Route::group(['prefix' => '/admin', 'namespace' => 'Gepard\Modules\Admin\Controllers', 'middleware' => 'admin'], base_path('app/Modules/Admin/Routes/routes.php'));
Route::group(['namespace' => 'Gepard\Modules\Page\Controllers'], base_path('app/Modules/Page/Routes/routes.php'));
Route::get('/', 'Gepard\Modules\Page\Controllers\[email protected]');
<?php
Route::get('/', '[email protected]')->name('sdf');
Route::get('/test/{id?}', '[email protected]');
Route::get('/profile/{user?}', '[email protected]')->name('a.user');
Route::get('/', 'Gepard\Modules\Page\Controllers\[email protected]');
Route::get('/', 'Gepard\Modules\Page\Controllers\[email protected]');
<?php namespace Gepard\Modules;
use Illuminate\Support\ServiceProvider;
/**
* Сервис-провайдер для подключения модулей
*/
class ModulesServiceProvider extends ServiceProvider {
public function boot()
{
$modules = config('module.modules');
if($modules)
{
foreach ($modules as $module)
{
if (file_exists(__DIR__.'/'.$module.'/Routes/routes.php'))
{
$this->loadRoutesFrom(__DIR__.'/'.$module.'/Routes/routes.php');
}
//Загружаем View
//view('Test::admin')
if(is_dir(__DIR__.'/'.$module.'/Views'))
{
$this->loadViewsFrom(__DIR__.'/'.$module.'/Views', $module);
}
//Миграции
if(is_dir(__DIR__.'/'.$module.'/Migrations'))
{
$this->loadMigrationsFrom(__DIR__.'/'.$module.'/Migrations');
}
//Переводы
if(is_dir(__DIR__.'/'.$module.'/Lang'))
{
$this->loadTranslationsFrom(__DIR__.'/'.$module.'/Lang', $module);
}
}
}
}
public function register()
{
}
}
protected function mapModulesRoutes()
{
Route::middleware('web')
->group(base_path('routes/modules.php'));
}
Answer the question
In order to leave comments, you need to log in
Well, in my opinion, everything is obvious - in your ModuleLoader you load routes directly from __DIR__.'/'.$module.'/Routes/routes.php' (app_path() is better, but oh well), and, most likely, you connect this provider after the default Laravel one, which loads routes/modules
Either use one (and groups inside the corresponding modules is a more correct solution) or another (your modules.php, but this is a crazy implementation, given that laravel allows you to do more (and you have already done it))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question