laravel的路由
Posted volition丶L
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel的路由相关的知识,希望对你有一定的参考价值。
laravel的每个操作都要写一个路由
laravel的路由要写在routes里的web.php
代码如下
use App\\Http\\Resources\\User as UserResource; use App\\Model\\Test\\User; //Route::get(\'/\', function () { // return view(\'welcome\'); //}); //Route::get(\'/haha\', function () { // return \'hehehe\'; //}); Route::get(\'/\',function (){ return view(\'welcome\'); }); Route::get(\'/a\',\'Admin\\AdminController@hello\'); //闭包函数 //use Illuminate\\Support\\Facades\\View; Route::get(\'/\',function() { // return view(\'weloce\'); //转换为json // return[ // \'a\' =>\'aaaa\', // \'b\'=>\'bbbb\' // ]; //转换为数组 // return [1, 2, 3]; //自定义HTTP状态码 // return response(\'Hello World\', 404) // ->header(\'Content-Type\', \'text/plain\'); //添加响应头 // return response(\'$content\',200) // ->header(\'Content-Type\', \'text/plain\'); //添加cookie到响应 // return response(\'$content\',200) // ->header(\'Content-Type\', \'a=10\'); //跳转页面 // return redirect(\'Admin\\UserController@hello\'); //返回 // return back()->withInput(); //数组转换为 JSON : // return response()->json([ // \'name\' => \'Abigail\', // \'state\' => \'CA\' // ]); //判断视图文件是否存在 // dd(View::exists(\'emails.customer\')); // return view(\'weloce\'); }); //Route::any(\'users/{id}\',"Admin\\UserController@hello"); Route::view(\'text\',\'text.text\'); Route::get(\'/mysql\',\'UserController@index\'); Route::get(\'/model\',\'UserController@test\'); Route::any(\'/res\',function (){ return new UserResource(User::find(1)); }); Route::get(\'/get\',\'TestController@get\'); Route::view(\'index\',\'index\'); Route::view(\'img\',\'alert\'); Route::any(\'user/{a?}\',"TestController@test")->middleware(\'test\'); //Route::any(\'users/{id}\',"Admin\\UserController@hello")->name(\'h\'); //Route::any(\'users/hello\',"Admin\\UserController@hello")->name(\'h\'); //
view 如果
以上是关于laravel的路由的主要内容,如果未能解决你的问题,请参考以下文章