Reputation: 1607
I am trying to pass some data from my view to my controller in order to display data using the selected month, I am not sure if the month numbers or the Eloquent query I am doing is correct, here is what I have got so far.
My routes:
Route::get('dcmlog/monthly','LogController@monthly');
Route::resource('dcmlog', 'LogController');
Controller:
public function monthly($id)
{
$dcmlogs = log::with('users')
->whereMonth('created_at', '=', $id))
->paginate(15);
return view('dcmlog.index', compact('dcmlogs'));
}
My index view:
<h>Display a logs by month <h>
<a href="{{action('LogController@monthly'),$post['id'] }}">
{{ $id=Form::selectMonth('month')}}</a>
I am getting the following error when running the page
Missing required parameters for [Route: ] [URI: dcmlog/monthly/{id}].
Upvotes: 1
Views: 1980
Reputation: 2514
Missing id parameter in route:
Route::get('dcmlog/monthly','LogController@monthly');
should be
Route::get('dcmlog/monthly/{id}','LogController@monthly');
and Action syntax has error:
<a href="{{action('LogController@monthly'),$post['id'] }}">
should be
<a href="{{action('LogController@monthly', $post['id']) }}">
URL generation for controllers action
Upvotes: 1
Reputation: 1188
Add a router: Route::get('dcmlog/monthly/{id}','LogController@monthly')->name('blah');
Pass id
var as parameter in view <a href="{{action('LogController@monthly'),$post['id'] }}">
or {{route('blash',['id'=>$post['id']])}}
Upvotes: 2
Reputation: 5042
You are missing to add an id
in your route. Just add it and you've fixed!
See this docs for more info!
Add it Like:
Route::get('dcmlog/monthly/{id}','LogController@monthly');
Upvotes: 1
Reputation: 9369
Add ID parameter to your route like this
Route::get('dcmlog/monthly/{id}','LogController@monthly');
After this you can access the value of id in your controller.
You can see docs here https://laravel.com/docs/5.6/routing#required-parameters
Upvotes: 2