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\[email protected]‘); //闭包函数 //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\[email protected]‘); //返回 // return back()->withInput(); //数组转换为 JSON : // return response()->json([ // ‘name‘ => ‘Abigail‘, // ‘state‘ => ‘CA‘ // ]); //判断视图文件是否存在 // dd(View::exists(‘emails.customer‘)); // return view(‘weloce‘); }); //Route::any(‘users/{id}‘,"Admin\[email protected]"); Route::view(‘text‘,‘text.text‘); Route::get(‘/mysql‘,‘[email protected]‘); Route::get(‘/model‘,‘[email protected]‘); Route::any(‘/res‘,function (){ return new UserResource(User::find(1)); }); Route::get(‘/get‘,‘[email protected]‘); Route::view(‘index‘,‘index‘); Route::view(‘img‘,‘alert‘); Route::any(‘user/{a?}‘,"[email protected]")->middleware(‘test‘); //Route::any(‘users/{id}‘,"Admin\[email protected]")->name(‘h‘); //Route::any(‘users/hello‘,"Admin\[email protected]")->name(‘h‘); //
view 如果
原文地址:https://www.cnblogs.com/LQK157/p/11474662.html
时间: 2024-10-03 15:48:40