本文介绍了Laravel-如何使用观察者检查更新哪一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想了解使用观察者进行了bieng更新的一列

I want to know about only one column which is bieng updated using observer

<?php


namespace App\Observers;


use App\OnsiteHistory;

class OnsiteHistoryObserver
{

    public function updated(OnsiteHistory $onsiteHistory)
    {
        if ($onsiteHistory->status == 'accepted'){

           // send email  

        }
    }
}

我只想检查状态列是否已更新.我该怎么办?

I want to check only status column is updated.How do I can do that?

推荐答案

经过一番研究并查看了Laravel的源代码之后,我找到了解决方法.

After the bit of research and looking in to the Laravel source I have found way to do it.

Laravel Elouqont提供了一种方法isDirty([])

Laravel Elouqont provides a method isDirty([])

namespace App\Observers;


use App\OnsiteHistory;

class OnsiteHistoryObserver
{

    public function updated(OnsiteHistory $onsiteHistory)
    {
        if ($onsiteHistory->isDirty(['status']) &&  strtolower($onsiteHistory->status) == 'accepted'){

       dd('I am updated')


        }
    }
}

这篇关于Laravel-如何使用观察者检查更新哪一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:10