Reputation: 1220
i created a resource route like :
Route::resource('club.user' , 'UserClubController');
to create users from a club . everything is fine when i want to display the blade view 'create' but when i want to store the user i get an error like :
Missing required parameters for [Route: club.user.store] [URI: club/{club}/user]. (View: /Applications/XAMPP/xamppfiles/htdocs/adminlte/resources/views/users/createUserClub.blade.php)
Here my blade view to create a new user for the club :
{!! Form::open(array('route' => 'club.user.store' , 'method' => 'POST')) !!}
here my function create from the UserClubController
public function create($club)
{
$club = Club::findOrFail($club);
$role = Role::pluck('title' , 'id') ;
return view('users/createUserClub' , compact('role' , 'club'));
}
here my store Controller :
public function store(Request $request){
$user = new User;
$user->name = $request->input('name');
$user->email = $request->input('email');
$user->password = bcrypt($request->input('password'));
$type_structure = TypeStructure::where('id' , '=' , '4')->first();
$user->type_structure_id = $type_structure->id;
dd($user);
$user->save();
someone have an idea to resolve this issue ? thanks a lot in advance :)
Upvotes: 1
Views: 5107
Reputation: 6802
It's basically exactly what the error tells you. You are using Route::resource and a nested model (club -> has many users)
If you now want to use
Route::resource('club.user' , 'UserClubController');
It means that every access to a user is via the specific club. You will therefore have the following routes
/club/{club}/user | GET, POST
/club/{club}/user/{user} | GET, PUT / PATCH, DELETE
You will need to provide this club paramter within your blade view
{!! Form::open(array('route' => ['club.user.store', $club->id] , 'method' => 'POST')) !!}
Upvotes: 2