mardi 2 avril 2019

Laravel copy data from one model instance to another object (child of the first)

Supose this Eloquent Model:

class User extends Model
{
    protected $table = 'users';
}

And this one:

class DeletedUser extends User
{
    public function someDeletedUserFunction()
    {
        // ... some stuff here
    }
}

If I do $user = User::find(1) and $deletedUser = new DeletedUser(), how can I copy the data inside $user object to the $deletedUser object?

I am trying to use $deletedUser->attributes = $user->getAttributes, and it is fine, but I cant do it with original attributes and another internal object data.

How can achieve this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Up6bSp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire