企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
##路由文件 每个模块都包含自己的路由文件,均位于 Routes 下,默认情况下包含以下四个 ~~~ admin.php // 后台路由 api.php //api路由 front.php // 前台路由 console.php //命令行路由 ~~~ ## 后台路由 admin.php ~~~ <?php use Illuminate\Routing\Router; // Test 模块后台路由 $router->group(['prefix'=>'test', 'module'=>'test'], function (Router $router) { // test group example $router->group(['prefix' =>'test'], function (Router $router) { $router->get('index','TestController@index')->name('test.test.index')->middleware('allow:test.test.index'); $router->get('create','TestController@create')->name('test.test.create')->middleware('allow:test.test.create'); $router->post('store','TestController@store')->name('test.test.store')->middleware('allow:test.test.store'); $router->get('show/{id}','TestController@show')->name('test.test.show')->middleware('allow:test.test.show'); $router->get('edit/{id}','TestController@edit')->name('test.test.edit')->middleware('allow:test.test.edit'); $router->put('update/{id}','TestController@update')->name('test.test.update')->middleware('allow:test.test.update'); $router->delete('destroy/{id}','TestController@destroy')->name('test.test.destroy')->middleware('allow:test.test.destroy'); }); }); ~~~ 每个控制器都建议使用路由分组 后台部分每个路由都包含: 路由名称:name 权限控制:middleware('allow:test.index'); 路由分组里面增加了 'module'=>'test' 项,用于识别模块,其他和laravel并无区别 备注1:不支持 laravel中route的resouce方法 备注2:可以在控制器建好后,使用 开发助手-模块开发助手-模块-控制器,找到对应的控制器,查看路由参考,复制并粘贴 ## 前台路由 front.php 类似于admin路由,参考上面文档 ``` <?php use Illuminate\Routing\Router; // Core 模块前台路由 $router->group(['prefix' =>'/','module'=>'core'], function (Router $router) { $router->get('/', 'IndexController@index')->name('index'); $router->get('cms', 'IndexController@index')->name('cms'); }); ``` ## Api路由 api.php 参考上面文档 ## 命令行路由:console.php 可以参考laravel的命令行路由,代码示例,增加 php artisan zotop:version 和 php artisan thumbnail:clear命令 ``` <?php /** * 显示当前版本信息 */ Artisan::command('zotop:version', function () { $name = $this->laravel['config']->get('zotop.name'); $version = $this->laravel['config']->get('zotop.version'); $release = $this->laravel['config']->get('zotop.release'); $this->info($name.' version:'.$version.'('.$release.')'); })->describe('Show the version of zotop'); /** * 清理图片缩略图 */ Artisan::command('thumbnail:clear', function () { $dir = public_path('thumbnails'); foreach ($this->laravel['files']->directories($dir) as $subdir) { $this->laravel['files']->deleteDirectory($subdir); } $this->info('Image thumbnail files cleared!'); })->describe('Clear the image thumbnail files'); ```