Laravel 5.6 - Error passing 2 parameters in url

Asked

Viewed 519 times

0

Hello, I am trying to pass 2 parameters to my controller using url and am getting the following error message:

Missing required Parameters for [Route: Teacher.average_faults] [URI: teacher/Average-faults/{team}{Matter}].

my view is like this:

<a href="{{route('teacher.average_faults',[$team->id,$matter->id])}}"></a>

my controller:

public function closureTeacherAverage_Faults($team, $matter){
    $verify = Closure::find(1);
    $team = Team::find($team);
    $matter = Matter::find($matter);

    $students_ids = DB::table('student_team')->select('student_id')->where('team_id','=',$team->id)->pluck('student_id');

    $students = [];
    foreach ($students_ids as $value) {            
        $students[] = montar(Student::find($value));
    }

    return view('closure.averages_faults',compact('verify','students','matter'));
}

my web route is like this:

Route::get('professor/average-faults/{team}{matter}',   ['as' => 'teacher.average_faults', 'uses' => 'Employee\ClosureController@closureTeacherAverage_Faults']);

If anyone can help, I’d appreciate it.

  • I believe you will have complications using the url in this format, but you can do it like this: <a href="{{ route('teacher.average_faults',['team' => $team->id, 'matter' => $matter->id])}}"></a>

  • Why not use a separator to define your route? Route::get('professor/average-faults/{team}/{matter})

  • I did what you said but it continues with the same error of Missing Parameters... =/ yes I tmb modified putting a separator as you showed above. error --> Return new Static("Missing required Parameters for [Route: {$route->getName()}] [URI: {$route->Uri()}].");

  • I was able to fix, leaving one parameter as main and another as optional. so--> Route::get('listMatters/{team}/{Matter? } I found the complete answer here --> https://laracasts.com/discuss/channels/laravel/how-to-pass-two-arguments-to-controller

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.