[英]laravel pass data from View to controller : Missing required parameters for [Route: ]
我試圖將某些數據從我的視圖傳遞到我的控制器,以便使用選定的月份顯示數據,我不確定我正在執行的月份數或Eloquent查詢是否正確,這就是到目前為止的結果。
我的路線:
Route::get('dcmlog/monthly','LogController@monthly');
Route::resource('dcmlog', 'LogController');
控制器:
public function monthly($id)
{
$dcmlogs = log::with('users')
->whereMonth('created_at', '=', $id))
->paginate(15);
return view('dcmlog.index', compact('dcmlogs'));
}
我的索引視圖:
<h>Display a logs by month <h>
<a href="{{action('LogController@monthly'),$post['id'] }}">
{{ $id=Form::selectMonth('month')}}</a>
運行頁面時出現以下錯誤
[路由:] [URI:dcmlog /每月/ {id}]缺少必需的參數。
像這樣向您的路線添加ID參數
Route::get('dcmlog/monthly/{id}','LogController@monthly');
之后,您可以訪問控制器中的id值。
您可以在這里查看文檔https://laravel.com/docs/5.6/routing#required-parameters
添加一個路由器: Route::get('dcmlog/monthly/{id}','LogController@monthly')->name('blah');
通過id
var當成參數鑒於<a href="{{action('LogController@monthly'),$post['id'] }}">
或{{route('blash',['id'=>$post['id']])}}
您缺少在路線中添加id
的信息。 只需添加它就可以了!
有關更多信息,請參見此文檔 !
像這樣添加:
Route::get('dcmlog/monthly/{id}','LogController@monthly');
路線中缺少ID參數:
Route::get('dcmlog/monthly','LogController@monthly');
應該是Route::get('dcmlog/monthly/{id}','LogController@monthly');
和動作語法有錯誤:
<a href="{{action('LogController@monthly'),$post['id'] }}">
應該是
<a href="{{action('LogController@monthly', $post['id']) }}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.