phpvms/resources/stubs/modules/route-provider.stub

96 lines
2.4 KiB
Plaintext
Raw Normal View History

2017-12-14 12:24:41 +08:00
<?php
namespace $NAMESPACE$;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
2017-12-14 12:24:41 +08:00
/**
* Register the routes required for your module here
*/
class RouteServiceProvider extends ServiceProvider
2017-12-14 12:24:41 +08:00
{
/**
* The root namespace to assume when generating URLs to actions.
*
* @var string
*/
protected $namespace = '$MODULE_NAMESPACE$\$MODULE$\Http\Controllers';
2017-12-14 12:24:41 +08:00
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*
* @param Router $router
* @return void
*/
public function before(Router $router)
{
//
}
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
*
2017-12-14 12:24:41 +08:00
* @return void
*/
public function map(Router $router)
{
$this->registerWebRoutes();
$this->registerAdminRoutes();
$this->registerApiRoutes();
}
/**
*
*/
protected function registerWebRoutes(): void
{
$config = [
'as' => '$LOWER_NAME$.',
'prefix' => '$LOWER_NAME$',
'namespace' => $this->namespace.'\Frontend',
'middleware' => ['web'],
];
Route::group($config, function() {
$this->loadRoutesFrom(__DIR__.'/../Http/Routes/web.php');
});
}
protected function registerAdminRoutes(): void
{
$config = [
'as' => 'admin.$LOWER_NAME$.',
'prefix' => 'admin/$LOWER_NAME$',
'namespace' => $this->namespace.'\Admin',
'middleware' => ['web', 'role:admin'],
];
Route::group($config, function() {
$this->loadRoutesFrom(__DIR__.'/../Http/Routes/web.php');
});
}
/**
* Register any API routes your module has. Remove this if you aren't using any
*/
protected function registerApiRoutes(): void
{
$config = [
'as' => 'admin.$LOWER_NAME$.',
'prefix' => 'admin/$LOWER_NAME$',
'namespace' => $this->namespace.'\Api',
'middleware' => ['api'],
];
Route::group($config, function() {
$this->loadRoutesFrom(__DIR__.'/../Http/Routes/api.php');
});
2017-12-14 12:24:41 +08:00
}
}