简体   繁体   中英

Too few arguments to function App\Http\Controllers 0 passed and exactly 2 expected"

I know there are solutions but none of them working for me. Here is my hyperlink

<a href="{{route('voting',$parameters = array('id' =>$answers->id,'votes' =>"1"))}}"><span class="glyphicon glyphicon-chevron-up"></span></a>

This is my route First i tried this one

 Route::get('voting','AnswerController@voting')->name("voting");

then this one

Route::get('voting',array('as'=>'voting','uses'=>'AnswerController@voting'));

My Controller

public function voting($id,$votes){
        //rest  of code 
}

problem i am facing

"Too few arguments to function App\\Http\\Controllers\\AnswerController::voting(), 0 passed and exactly 2 expected"

I believe you need to give the route 2 parameters

Route::get('voting/{id}/{votes}', array('as'=>'voting','uses'=>'AnswerController@voting'));

Refer to this thread

Passing multiple parameters to controller in Laravel 5

Use this

<a href="{{ route('voting',['id' => $answers->id, 'votes' => 1]) }}"><span class="glyphicon glyphicon-chevron-up"></span></a>

Instead of

<a href="{{route('voting',$parameters = array('id' =>$answers->id,'votes' =>"1"))}}"><span class="glyphicon glyphicon-chevron-up"></span></a>

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