shopApi分类观察者

一、创建分类观察者

 php artisan make:observer CategoryObserver --model=Category

二、在CategoryObserver观察者类中写入方法

public function create(Category $category)

{

  forget_cache_category();

}

public function updated(Category $category)

{

  forget_cache_category();

}

三、在AppServiceProvider服务提供者类中添加

在AppServiceProvider类的boot方法中添加

Category::observe(CategoryObserver::class);

 

四、在控制器中模型调用

Category::create();

$category->update();

sertData);

posted @ 2023-01-31 19:27  深山居士123  阅读(41)  评论(0)    收藏  举报