Actually I am facing a problem. I need to send a notification to the admin whenever any update happens in any modal, in any user, and in any table.
To clarify more :
I have a client, a company, and an employee. Under each part, I have many tables ( e.g: under client I have client's profile table, under company I have many tables corresponding to company's lawyer, company's files, etc.., similarly to the employee)
So correspondingly , I have many controllers thus many update methods.
So In order to send a notification to the admin whenever any update happens in any situation under any user. It's too annoying that I must include the notify statement $admin->notify(new UpdateIsMade()); under ALL update METHODS!
It's kind of redundancy.
What I want to actually approach is to find a solution that let me automatically send a notification to the admin whenever any update happens by any user under any table.
I tried to make a middleware function and tried to send a notification whenever any update happens under the client user (kind of sampling) :
public function handle(Request $request, Closure $next)
{
$clients = \App\Client::all();
foreach ($clients as $client) {
if($client->user->wasChanged()){
$arr_of_changes = $client->user->getChanges();
$admin=User::where('profile_type' , 'App\Admin')->first();
$admin->notify(new UpdateIsMade($arr_of_changes,$original_arr));
}
}
return $next($request);
}
Unfortunately this middleware didn't work.
I guess the problem is that $client->user->wasChanged() is not giving a true value whenever an update happens. It looks like wasChanged only works after the save process in the update method.
Any suggestion for my problem? Thank you for your time and sorry for the long text!