sme/laravel-model-life-events 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sme/laravel-model-life-events

Composer 安装命令:

composer require sme/laravel-model-life-events

包简介

README 文档

README

This library allows you to extend the work of Models life cycle methods in Laravel Framework

Install:

composer require sme/laravel-model-life-events

For example:

class Posts extends Model
{
	public static function booted() {

		self::deleted(function (self $model) {

			//  listening to the deletion event in the current model
			...

		});

	}

For this code, the listener will not work because the method calling the deleted event is missing from the Builder class

public static function deletePost(int $post_id) {
	return self::where('id', $post_id)->delete();
}

you can use the find($post_id) method then everything will work, but it is not always convenient

public static function deletePost(int $post_id) {
	$post = self::find($post_id);
	if ($post) {
		return $post->delete();
	}
}

To use the delete or update methods without additional first, find, etc. methods. You can use trait "HasEvents" in your models class

use SME\Laravel\Model\HasEvents;

class Posts extends Model
{
	use HasEvents;
	
	...

In this case, listeners such as "deleting" or "updating" are always called, and "deleted" or "updated" are called only if the request was successful

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-07