How to pass additional parameters on the observer model events (and model custom events) of Laravel

reference documentation

for example:

class MyObserver
{
    public function saving(Model $model)
    {
        // $model
    }
}

this method is currently used to deal with it:

protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }
   

although it is said that the current problem can be solved, I hope to be able to modify it in a similar way:

public function saving(Model $model, argument1, argument2....)

ask for advice on how to achieve this thought, or some other more convenient method, thank you

Mar.08,2022

look at the source code should not work, only you can inject


refer to the following code to add attributes to Model. At this point, the custom properties are also passed to the observer.

<?php

class UserObserver {

    public function saving(User, $user) {
        echo $user->argument1;
        echo $user->argument2;
    }

}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c795-2bb6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c795-2bb6c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?