L5.5 模型观察者怎么不执行?
大概想实现的就是用户积分发生变化的时候给用户发送通知
一共是3个文件:用户积分模型,观察者,修改 AppServiceProvider.php 里注册,(管理后台使用积分模型)更改用户积分的时候,没有反应,没有报错,也没执行观察者内的逻辑,我自己手动添加日志,也没有进入。
观察者代码
namespace App\Observers;
use App\Models\Point;
use Illuminate\Support\Facades\DB;
class PointObserver
{
private $client_id = '';
private $encryption_key = '';
private function send_msg(Point $point)
{
//TODO 执行发送逻辑
addlog('执行发送逻辑');
}
function created(Point $point) {
addlog('进入 created');
$this->send_wechat_tmpl_msg($point);
}
function saved(Point $point) {
addlog('进入 saved');
$this->send_wechat_tmpl_msg($point);
}
function updated(Point $point) {
addlog('进入 updated');
$this->send_wechat_tmpl_msg($point);
}
function deleted(Point $point) {
addlog('进入 deleted');
$this->send_wechat_tmpl_msg($point);
}
AppServiceProvider.php 里在boot 内注册:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Models\Point;
use App\Observers\PointObserver;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() {
Point::observe(PointObserver::class);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
请教是不是缺少了什么步骤顺便请教怎么调试
推荐文章: