2016-10-10 49 views
0

我需要一些幫助,請Laravel - 的hasMany CRUD - 更新

我有兩個表:運營商銷售

Image of Yaktocat http://i67.tinypic.com/2uj6znn.png Image of Yaktocat http://i67.tinypic.com/er0c90.png

載波CRUD工作。出售CRUD也在工作,除了更新方法。

爲了更新,我需要carrierId出售編號,對吧?

這是我CarrierSellController:

Image of Yaktocat http://i63.tinypic.com/2z40pjs.png

這是我運營商/銷售/ edit.blade.php

Image of Yaktocat http://i65.tinypic.com/2j2i8fs.png

模型結合工作:

Image of Yaktocat http://i65.tinypic.com/16lb1l.png

表單行爲在網址的末尾有/編輯。沒問題?

Image of Yaktocat http://i63.tinypic.com/25zmmas.png

如果我點擊提交按鈕,我得到這個錯誤:

Image of Yaktocat http://i65.tinypic.com/b3os2q.png

+0

因爲路線/車riers/{carrierID}/sell/{id}/edit不聲明。 –

+0

我建議你必須使用 - > where('id','[0-9] +'); –

+0

在這張圖片上,你只需更新:我看到的方法是GET。請更改爲POST。 –

回答

0

試試這個一個

{!! Form::model($sell,['url'=>url('carriers/'.$sell->carrier->id.'/sell/'.$sell->id),'method'=>'patch']) !!} 

,並在銷售模型添加

public function carrier() 
{ 
    return $this->belongsTo(Carrier::class); 
} 
+0

謝謝!!!!!!!!!! – confm

0

確保方法是PUT

添加到您的形式

{{ method_field('put') }} 
+0

嗨,謝里夫,謝謝你的回答。 HTTP://oi68.tinypic。COM/2ypcig5.jpg。點擊更新按鈕後,我得到此錯誤:RouteCollection.php中的MethodNotAllowedHttpException行218: – confm

0

你爲什麼不,如果你想絕對肯定只是嘗試宣告路線喜歡自己:

Route::put('carriers/{carrierId}/sell/{id}', [ 'as' => 'carriers.sell.update', 'uses' => '[email protected]' ]); 

然後在你看來有這個:

{!! Form::model($sell, ['method' => 'PUT', 'route' => ['carriers.sell.update', 'carrierId' => $sell->carrier->id, 'id' => $sell->id]) !!}