Php 发生更新事件时发送通知

Php 发生更新事件时发送通知,php,laravel-5.8,Php,Laravel 5.8,我可以发誓我的代码到现在为止一直在工作。我正在观察一个项目模型,希望在状态列为udpdate且设置为已加载时发送电子邮件通知。为此,我使用了isDirty()方法,但我的代码似乎不起作用,因为没有发送邮件。这是我的密码 use App\Notifications\ItemAlert; use App\User; use App\Item; class ItemObserver { public function updated(Item $item) { //

我可以发誓我的代码到现在为止一直在工作。我正在观察一个项目模型,希望在
状态
列为udpdate且设置为
已加载
时发送电子邮件通知。为此,我使用了
isDirty()
方法,但我的代码似乎不起作用,因为没有发送邮件。这是我的密码

use App\Notifications\ItemAlert;
use App\User;
use App\Item;


class ItemObserver
{
    public function updated(Item $item)
    {
        // check if product status was updated to loaded
        if ($item->isDirty('status' === 'Loaded')) {

            // notify all users
            $users = User::all();

            foreach ($users as $user) {
                $user->notify(new ItemAlert($user, $item));
            }
        }
    }
}

我需要帮助才能工作。

问题解决了!显然,
isDirty()
需要第二个条件来检查丢失了哪个。正确的代码应该是

public function updated(Item $item)
    {
        // check if product status was updated to loaded
        if ($item->isDirty('status' === 'Loaded') && ($item->status === 'Loaded')) {

            // notify all users
            $users = User::all();

            foreach ($users as $user) {
                $user->notify(new ItemAlert($user, $item));
            }
        }
    }
我希望这能帮助任何遇到这个解决方案的人