lundi 9 août 2021

Laravel detect mass assigning

I have a model event defined on a model that each time a create a record I add the user's company id related to that record.

All works fine but I'm mass assigning records through csv importation and I must set the company id set as null.

How can I detect in Laravel when I'm massive assigning?

This is my model event:

protected static function boot()
    {
        parent::boot();

        static::creating(function (Product $model) {
            $model->company_owner_id = session()->get('currentCompany.id');
        });
    }

I've not done the controller's function that stores the records created through CRUD form neither the csv importer and both are strongly used by all the Laravel app so I have no chance to modify the importer or CRUD form.

Before using the csv importer the $fillable attribute on the model wasn't defined.



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

Aucun commentaire:

Enregistrer un commentaire