Route::resource('re','Admin\ReController');
Controller php
<?php namespace App\Http\Controllers\Admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Input; class ReController extends Controller { //get.re 所有分類列表 public function index($id = null){ echo "這裏是index方法不能傳入參數"; } //get.re/create 添加分類 public function create(){ echo "這裏是create方法不能傳入參數"; } //post.re 添加分類提交 public function store(){ echo "這裏是store方法不能傳入參數"; } //get.re/{id} 顯示單個分類 public function show($id){ echo "這裏是show方法傳入的參數是:".$id; dd(Input::all()); } //get.re/{id}/edit 更新分類 public function edit($id){ echo "這裏是edit方法傳入的參數是:".$id; dd(Input::all()); } //put.re/{id} 顯示單個分類信息 public function update($id){ echo "這裏是update方法傳入的參數是:".$id; dd(Input::all()); } //delete.re/{id} 刪除單個分類 public function destroy($id){ echo "這裏是destory方法傳入的參數是:".$id; dd(Input::all()); } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> </head> <body> <form action="{{url('re')}}" method= "get"> <input type="submit" value="這裏是index方法" /> </form> <form action="{{url('re/create')}}" method= "get"> <input type="submit" value="這裏是create方法" /> </form> <form action="{{url('re/')}}" method= "post"> {{csrf_field()}} <input type="submit" value="這裏是store方法" /> </form> <form action="{{url('re/123')}}" method= "get"> <input type="submit" value="這裏是show方法" /> </form> <form action="{{url('re/123/edit')}}" method= "get"> <input type="submit" value="這裏是edit方法" /> </form> <form action="{{url('re/123')}}" method= "POST"> <input type="submit" value="這裏是update方法" /> <input type="hidden" name="_method" value="PUT"> <input type="hidden" name="_token" value="{{csrf_token()}}" /> </form> <form action="{{url('re/123')}}" method= "post"> <input type="submit" value="這裏是destory方法" /> <input type="hidden" name="_method" value="DELETE"> <input type="hidden" name="_token" value="{{csrf_token()}}" /> </form> </body> </html>
總結:想快速學習一個框架莫過於寫博客了,在涉及傳遞參數的時候就懵逼了,網上搜索才發現有個資源路由。須要注意的就是原生的HTTP只支持get和post傳想要用laravel中的PUT,DELETE方法必需要加默認的隱藏input數據並且要接CSRF驗證html
轉自:https://blog.csdn.net/jiavv5/article/details/60465038laravel