2017-09-24 114 views
0

我正在嘗試通過id進行搜索。laravel路由和參數

<form method="post" action="{{action('[email protected]')}}"> 
<input type="text" name="id"> 

控制器

public function edit(Request $request) 
    { 
     $id=$request->id; 
     $ply = Player::find($id); 
     return view::make('player.edit')->with(compact('ply')); 
    } 

路線

Route::get('/player/edit/{id}', '[email protected]'); 

edit.blade.php

<td>{{$ply[first_name]}}</td> 

我越來越不確定的變量FIRST_NAME錯誤。

回答

0

路線必須是如下自交reuqest

Route::post('/player/edit', '[email protected]'); 

,你也可以在形式上做動作如下

<form method="post" action="{{url('/player/edit')}}"> 
<input type="text" name="id"> 

,如果你想使GET請求,那麼你必須改變控制器到

public function edit($id) 
     { 

      $ply = Player::find($id); 
if($ply){ 
      return view::make('player.edit')->with(compact('ply')); 
} 
     } 
+0

@ KenGraham.if其有用的標記答案被接受。 – iCoders

+0

@ KenGraham.glade在這裏它幫助你 – iCoders

0

$ply是一個對象。試試這個

<td>{{ $ply->first_name }}</td> 

這不會引起任何錯誤,如果$ply對象是null

而且,你並不需要在你的路線{id}參數。因爲您通過發佈請求獲取了ID。

Route::get('/player/edit', '[email protected]');