0

I once did an eager loading query and it worked. Then using model binding i'm trying to update my two tables at once with no lucky. No error thrown, all validations are fine and when i tried to var_dump to see the values after validation , they are all there. I just can't get a way to update two tables in database using eloquent at a time. Please help.

Here is what i did so far:

ProfilesController.php

public function update($username)
{
    $user = $this->getUserByUsername($username);

    $input = Input::all();

try {
    $this->profileForm->validate($input);

    // dd($input);

    $user->profile->update($input);



    } catch (FormValidationException $e) {
        return Redirect::back()->withInput()->withErrors($e->getErrors())->with('form_error', 'Sorry, we can not update your profile. Try again!');
    }

    return Redirect::route('profile.edit', $user->username)->with('form-success', 'Profile has been successfully updated!');
}


public function getUserByUsername($username)
{
    return User::with('profile')->whereUsername($username)->firstOrFail();
}

Other files can be found here: http://laravel.io/bin/8eJK5

Daniel Chikaka
  • 1,432
  • 4
  • 17
  • 28
  • Eloquent can't update 2 models in one `update` called on one of those models. You need to update the models separately. – Jarek Tkaczyk Jun 27 '14 at 08:57
  • I have tried saving them separately, only users table is updated. Please write some code to demonstrate that if you wont mind @deczo – Daniel Chikaka Jun 27 '14 at 10:38

0 Answers0