mercredi 28 juillet 2021

Laravel Mutator to add predefined values into database

I'm new into Laravel and I'm trying to store the user's company id on a column of the products table each time a user creates a new product. The company's id it's retrieved from the user's session. I'm trying it with Laravel's Mutator:

public function setFirstNameAttribute($value) {
        $this->attributes['company_id'] = session()->get('company.id');
    }

But each time I create a new Product the company id stored it's null. Seems like the function it's never executing. Is there any other resource to perform actions like this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire