具体安装环境可更具最新版本的文档来,一下内容 只是我代码的一些操作demo ,是对文档进行的个人笔记;
//路由命名
Route::get(‘admin‘,[‘as‘=>‘profile‘,function(){ echo route(‘profile‘); return ‘哈哈哈哈‘; }]); //控制器命名 //Route::get(‘admin‘,[‘as‘=>‘profile‘,‘uses‘=>‘Admin\AdminController@index‘]); 多个控制器命名 Route::get(‘admin‘,‘Admin\AdminController@index‘)->name(‘profile‘); Route::get(‘admin/login‘,‘Admin\AdminController@login‘)->name(‘profile‘); Route::get(‘article/index‘,‘Admin\ArticleController@index‘); Route::get(‘article/add‘,‘Admin\ArticleController@add‘); //后台路由分组 Route::group([‘prefix‘ => ‘admin‘,‘namespace‘ => ‘Admin‘,‘middleware‘=>[‘web‘,‘admin.login‘]], function () { Route::get(‘index‘, ‘AdminController@index‘); // Route::resource(‘article‘, ‘ArticleController‘); }); Route::group([‘prefix‘ => ‘article‘,‘namespace‘ => ‘Admin‘,‘middleware‘=>[‘web‘,‘admin.login‘]], function () { Route::get(‘index‘, ‘ArticleController@index‘); Route::get(‘add‘, ‘ArticleController@add‘); }); Route::get(‘home‘, ‘Home\UserController@show‘); //视图调用 Route::get(‘view‘,‘ViewController@index‘); //中间件 调用middleware admin.login Route::group([‘prefix‘ => ‘admin‘,‘namespace‘ => ‘Admin‘,‘middleware‘=>[‘web‘,‘admin.login‘]], function () { Route::get(‘index‘, ‘AdminController@index‘); // 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); //请求处理后执行 } }
本文出自 “kangjunfei” 博客,谢绝转载!
原文地址:http://kangjunfei.blog.51cto.com/11556647/1942748