lundi 16 juillet 2018

Laravel: Missing required parameters

I got the error missing required parameters, with the following route: Route::get('/myunits/{group}/content/{unit}','Users\GroupContentController@show')->name('user.group.unit.show');

The route is correct when we redirect to that route, but for some reason It fails. But when I do a dd() of the parameters on GroupContentController@show the parameters are there, so I don't understand where is the error.

This is my controller

public function show(Group $group , Unit $unit) {


    /*
    * Check if the user is trying to acces a group
    * here he does not belongs.
    */
    if ( !UserGroupFacade::IsStudentInGroup($group) ) {
        return redirect()->route('user.groups');
    }

    $data = [];
    $groupMaterials = $group->groupMaterials->where("unit_id" , $unit->id);

    foreach ($groupMaterials as $gm) {
        foreach ($unit->themes as $theme) {
            if ($theme->id == $gm->theme_id) {
                $theme->show=true;
                $material=$theme->materials->where("id" , $gm->material_id)->first();
                $material->show=true;
            }
        }
    }

    $data['unit'] = $unit;
    return view('users.units.show', array('data' => $data));
}

When I did a dd($group) and dd($unit) everything was there, even I tried that before the return and It stills working.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire