mfsymb
mfsymb

Reputation: 453

Laravel mass update

yesterday i asked a question about Eager Loading and Form Model Binding. Laravel Eager Loading and Form Model Binding

This is somehow a followup question.

Now i want to update the record in the Database

    $user = \User::findOrFail($id);
    $user->fill(\Input::all());
    $user->push();

But this dose only save the data of the user itself. Not the relations

user = saved
user->profile = not saved

on my user model i have a fillable array with all fillables columns. and on other models like the profile model i just wrote protected $fillable = ['*'];

Upvotes: 1

Views: 430

Answers (2)

mfsymb
mfsymb

Reputation: 453

The Soultion:

call fill() on the relations not just the user model.

$user->fill($input)
$user->profile->fill($input['profile'])

Upvotes: 2

c-griffin
c-griffin

Reputation: 3026

You're not retrieving profile with your user model.

$user = \User::with('profile')->findOrFail($id);

That should give you the profile properties to update.

Upvotes: 0

Related Questions