I have a user table which has a one to many relationship with profiles, a user can have one profile:
The problem is that I want to update the user page, and among the data I want to display all the names of the profiles in a select option in a form and the user can choose his profile.
Here is my code :
{!! Form::model($user, ['method' => 'PATCH','enctype'=>'multipart/form-data','route' => ['user.update', $user->id]]) !!}
//.....
<div class="form-group">
<label for="profil_id">Profile</label>
<input type="text" name="profil_id" class="form-control" value="">
<select>
<option></option>
</select>
</div>
<div class="form-group">
<input type="submit" value="Modifier" class="btn btn-info">
<a href="" class="btn btn-default">Cancel</a>
</div>
{!! Form::close() !!}
And my user controller update method :
public function update(UsersRequest $request, $id)
{
$user = Auth::user()->update($request->all());
return redirect()->route('user.index');
}
I have already set up the relationship in User and Profile models. Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire