2014-01-08 69 views
0

這是我做了一個成功的GET之後發出PUT請求的第一個破解我很興奮,然後按照教程我得到一個我不太明白的錯誤。在laravel中發出PUT請求?

以下是錯誤

"{"error":{"type":"ErrorException","message":"Undefined property: Symfony\\Component\\HttpFoundation\\ParameterBag::$name","file":"C:\\wamp\\www\\basketball-app-framework\\app\\controllers\\PlayersController.php","line":67}}"

我得到它的上線67和財產顯然是不確定的,但我也跟着教程,我不知道怎麼回事,寫這個,或者爲什麼它的不像教程那樣工作。我覺得這可能是因爲mod_rewrite,我有一個問題,並且必須在apache配置文件中設置一些東西來創建GET請求,所以我可能需要更改一些東西來創建PUT。

這是PUT數據的代碼。

public function update($id) 
{ 
    $input = Input::json(); 
    $player = Player::find($id); 
    $player->name = $input->name; // this is line 67 
    $player->save(); 
} 
再次錯誤occours與 $player->name = $input->name;

在我的表演方法

當我發送一個GET

public function show($id) 
{ 
    return Player::find($id); 
} 

Player::find($id);明顯作品

所以我的更新裏面的$player變量不應該是導致在訪問name屬性時遇到問題,所以我很茫然,希望有人能幫忙這個noob出來了。

謝謝。

回答

1

嘗試以下操作:

public function update($id) 
{ 
    $input = Input::all(); 
    $player = Player::find($id); 
    $player->name = $input['name']; 
    $player->save(); 
} 

或者試試這個:

public function update($id) 
{ 
     $player = Player::find($id); 
     $player->name = Input::get('name'); 
     $player->save(); 
} 
+0

哇感謝的人,它的工作我真的不知道怎麼辦,我可以任何其他方式都想通了這一點。 '$ input ['name']'實際上比'$ input-> name'更有意義。我希望我能給你更多的讚美,但非常感謝你的幫助。祝你有個好的一天! –

+1

只是爲了幫助你多一點,我經常使用這個'$ player-> fill(Input :: all())',它可以幫助你將所有屬性設置成一行:) – Andreyco

+0

謝謝,此時的所有提示更多比有價值的,我試圖得到這個新的流量的掛鉤。我花了很長時間學習backbone.js現在我需要掌握這一點。我很感激+1 –