Welcome Guest, Not a member yet? Register   Sign In
Pass multiple methods to $beforeInsert
#1

(This post was last modified: 11-02-2022, 09:28 AM by serialkiller.)

Maybe I didn't understand, but it's not possible to pass multiple methods to the $beforeInsertnel model variable, for example?

PHP Code:
protected $beforeInsert = ['methods1''methods2']; 

If I pass only one method it works, if I pass 2 it returns me: Trying to access array offset on value of type null
Reply
#2

No, it is possible to pass multiple methods.
You are doing something wrong.
Reply
#3

(This post was last modified: 11-03-2022, 06:53 AM by serialkiller.)

(11-02-2022, 02:37 PM)kenjis Wrote: No, it is possible to pass multiple methods.
You are doing something wrong.

I think so too, but what?


PHP Code:
protected $beforeInsert  = ['methods1''methods2'];
protected 
$beforeUpdate  = ['methods1'];


protected function 
methods1(array $data): array
{
    ...some stuff

    
return $data;
}


protected function 
methods2(array $data): array
{
    ...some stuff

    
return $data



Keeping in mind that what is contained in method 2 is a small part that was previously contained by method 1, therefore functioning without problems, now I need to differentiate a given operation only to the insert and not also to the update, so not to repeat the same code twice seemed to me the best choice to have the insert execute method 1 and method 2, but only method 1 for the update.

What's wrong with my code?
Reply
#4

Try to remove `...some stuff`. You would see no errors.
After that, debug your code.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB