I've have relation in my model:
public function profile()
{
return $this->hasOne('App\Models\Profile');
}
And form:
{!! Form::model($user, ['route' => ['profile.update'], 'method' => 'PATCH']) !!}
...
<div class="form_block"><span class="form_label">First Name</span>{!! Form::text('profile[first_name]') !!}</div>
...
The problem is, that by default relation is fetched "lazy" way, so I need to manually call $user->profile->first_name for form value. Or use something like this in controller:
$user_id = Auth::user()->id;
$user = User::with('profile')->find($user_id);
So maybe some eloquent have some option to control lazy load on relations? Didn't found any information about it.
Aucun commentaire:
Enregistrer un commentaire