具体安装环境可更具最新版本的文档来,一下内容 只是我代码的一些操作demo ,是对文档进行的个人笔记;
//路由命名
Route::get(‘admin‘,[‘as‘=>‘profile‘,function(){ echo route(‘profile‘); return ‘哈哈哈哈‘; }]); //控制器命名 //Route::get(‘admin‘,[‘as‘=>‘profile‘,‘uses‘=>‘Admin\[email protected]‘]); 多个控制器命名 Route::get(‘admin‘,‘Admin\[email protected]‘)->name(‘profile‘); Route::get(‘admin/login‘,‘Admin\[email protected]‘)->name(‘profile‘); Route::get(‘article/index‘,‘Admin\[email protected]‘); Route::get(‘article/add‘,‘Admin\[email protected]‘); //后台路由分组 Route::group([‘prefix‘ => ‘admin‘,‘namespace‘ => ‘Admin‘,‘middleware‘=>[‘web‘,‘admin.login‘]], function () { Route::get(‘index‘, ‘[email protected]‘); // Route::resource(‘article‘, ‘ArticleController‘); }); Route::group([‘prefix‘ => ‘article‘,‘namespace‘ => ‘Admin‘,‘middleware‘=>[‘web‘,‘admin.login‘]], function () { Route::get(‘index‘, ‘[email protected]‘); Route::get(‘add‘, ‘[email protected]‘); }); Route::get(‘home‘, ‘Home\[email protected]‘); //视图调用 Route::get(‘view‘,‘[email protected]‘); //中间件 调用middleware admin.login Route::group([‘prefix‘ => ‘admin‘,‘namespace‘ => ‘Admin‘,‘middleware‘=>[‘web‘,‘admin.login‘]], function () { Route::get(‘index‘, ‘[email protected]‘); // Route::resource(‘article‘, ‘ArticleController‘); }); 中间件5.4版本的文件在HTPP/Middleware下建立 //定义中间件 namespace APP\Http\Middleware; use Closure; class AdminLogin{ public function handle($request, Closure $next) { //请求处理前执行 session([‘admin‘=>null]); if(!session(‘admin‘)){ return redirect(‘admin/login‘); } //echo session(‘admin‘); return $next($request); //请求处理后执行 } }
时间: 2024-11-09 10:42:26