PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 6, 2022

[FIXED] Laravel detect mass assigning

 January 06, 2022     laravel, laravel-5     No comments   

Issue

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.


Solution

Finally I gave up on this and stopped to add the company_id on records as I can not determinate whether the records are created through csv importation or CRUD form.



Answered By - jcobo1
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing