2017-04-26 79 views
1

在我的Laravel路線文件(web.php)中,我有以下路線。Laravel寧靜的路線包含參數

Route::resource('notifications/{section_id}', 'NotificationController', ['as' => 'notifications']); 

我再有這將打開這樣

{!! Form::model($qList,['route' => ['notifications.store']]) !!} 

然而形式的刀模板,這一行產生一個錯誤,說Route [notifications.store] not defined.

運行php artisan route:list我可以看到路由名稱是notifications.{section_id}.store 。即路由名稱中包含{section_id}。這是我的問題嗎?參數似乎沒有被出現任何我的其他線路上,我有一個store方法在我NotificationController

感謝

+0

嘗試刪除{SECTION_ID }參數和路由:再次列出。 –

+0

這確實可行,並顯示正確的路線,但我需要將一個參數傳遞給我的控制器。需要{section_id} – Typhoon101

+0

轉儲商店方法內的$ request-> input('section_id')。不要忘記在方法實現中添加Request $ request作爲參數 –

回答

0

寫這樣,寫的全路徑名和傳遞SECTION_ID參數路線數組:

Form::model($qList,['route' => ['notifications.{section_id}.store', $section_id]]) 

然後,表單提交網址將成爲(假設99作爲部分ID)

<form method="POST" action="http://laravel5.dev/notifications/99" accept-charset="UTF-8"><input name="_token" type="hidden" value="..."> 

此外,您可以選擇強制你的REST風格的路線路線名稱與「名稱」參數,就像這樣:

Route::resource('notifications/{section_id}', 'TestController', ['as' => 'notifications', 'names' => ['store' => 'notifications.store']]); 

然後,用php artisan route:list你會看到

| Domain | Method       | URI           | Name          | Action          | Middleware | 
+--------+--------------------------------+------------------------------------------------+------------------------------------------+---------------------------------------------+--------------+ 
|  | POST       | notifications/{section_id}      | notifications.store      | App\Http\Controllers\[email protected] | web   | 
+0

這引導我走向正確的方向。謝謝你的幫助 – Typhoon101