简体   繁体   中英

laravel pass data from View to controller : Missing required parameters for [Route: ]

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}].

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

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']])}}

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'); 

Missing id parameter in route:
Route::get('dcmlog/monthly','LogController@monthly'); should be Route::get('dcmlog/monthly/{id}','LogController@monthly');

Routing with parameters

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM