Route::get($uri, $callback); Route::post($uri, $callback); Route::put($uri, $callback); Route::patch($uri, $callback); Route::delete($uri, $callback); Route::options($uri, $callback);
1 <form method="POST" action="/profile"> 2 {{ csrf_field() }} 3 ... 4 </form>
路由中書寫php
1 // put請求 2 3 Route::get('putWeb','LoginController@putWeb'); 4 5 // put的處理頁面 6 Route::put('put','LoginController@put');
控制器書寫laravel
1 // put請求頁面 2 3 public function putWeb(){ 4 5 return view('putWeb'); 6 } 7 8 // put請求處理頁面 9 public function put(Request $request){ 10 dd($request->input()); 11 }
請求頁面書寫web
1 <form action="put" method="post"> 2 <p> 3 {{csrf_field()}} 4 5 <input type="hidden" name="_method" value="put"> 6 User: 7 <input type="text" name="user" id=""> 8 </p> 9 </form>
1 Route::get('user/index','UserController@index'); 2 Route::get('user/add','UserController@add'); 3 Route::get('user/edit','UserController@edit'); 4 Route::post('user/insert','UserController@insert'); 5 Route::post('user/update','UserController@update'); 6 Route::get('user/del','UserController@del');
| GET|HEAD | Admin | Admin.index | App\Http\Controllers\IndexController@index | web | #展現頁面 | POST | Admin | Admin.store | App\Http\Controllers\IndexController@store | web | #添加操做 | GET|HEAD | Admin/create | Admin.create | App\Http\Controllers\IndexController@create | web | #添加頁面 | DELETE | Admin/{Admin} | Admin.destroy | App\Http\Controllers\IndexController@destroy | web | #刪除操做 | PUT|PATCH | Admin/{Admin} | Admin.update | App\Http\Controllers\IndexController@update | web | #更新操做 | GET|HEAD | Admin/{Admin} | Admin.show | App\Http\Controllers\IndexController@show | web | | GET|HEAD | Admin/{Admin}/edit | Admin.edit | App\Http\Controllers\IndexController@edit | web | #修改頁面 | GET|HEAD | api/user | | Closure | api,auth:api |
Route::get('UserInfo/{name}/{sex}',"IndexController@UserInfo"); // 新建UserInfo public function UserInfo($a,$sex1){ var_dump($a); var_dump($sex1); }
在Route的group方法中指定命名空間:Route::group(['namespace'=>'Admin'],function(){api
1 //路由中代碼 2 Route::group(['namespace'=>'Admin'],function(){ 3 Route::get('admin','IndexController@index'); 4 Route::get('admin/user','UserController@index'); 5 Route::get('admin/goods','GoodsController@index'); 6 }); 7 8 Route::group(['namespace'=>'Home'],function(){ 9 Route::get('/','IndexController@index'); 10 }); 11 #須要在控制器目錄下新建Admin目錄和Home目錄 在目錄中新建控制器 12 #注意 須要修改命名空間 13 14 控制器中代碼 15 <?php 16 17 namespace App\Http\Controllers\Admin; 18 19 use Illuminate\Http\Request; 20 21 use DB; 22 23 use App\Http\Controllers\Controller; 24 25 class UserController extends Controller 26 { 27 //index 方法 28 29 public function index(){ 30 31 echo "我是後臺控制器User"; 32 } 33 34 }