5 years ago

Refresh a Model?

Posted 5 years ago by daltonamitchell

Hey guys I'm testing some model relationsships and I'm curious if I can refactor my code a bit.

    // Assign User a role

    // Role should be admin
    $this->assertEquals('admin', $user->role[0]->name);

    // Change Users Role
    $user->role()->updateExistingPivot($admin->id, ['role_id' => $manager->id]);

    // Reload User
    $user = User::find(1);

At the end it seems I have to run a new query to get the updated relationship. Is there anyway to do something like this...

    // Reload User


    // Reload User

... get updated info after a save? It seems like if I'm using the same ID and everything I shouldn't have to create a new Model instance but maybe this is an instance where I should look into extending the framework for my edge case.

Please sign in or create an account to participate in this conversation.