2017-09-24 119 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]');