kobalazs/laravel-restrict-soft-deletes 问题修复 & 功能扩展

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

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

kobalazs/laravel-restrict-soft-deletes

Composer 安装命令:

composer require kobalazs/laravel-restrict-soft-deletes

包简介

Restrict deletes for Eloquent models that implement soft deletes.

README 文档

README

Restrict deletes for Eloquent models that implement soft deletes. Based on the idea of Michael Dyrynda at https://dyrynda.com.au/blog/cascading-soft-deletes-with-laravel-and-eloquent

Installation

Run composer require kobalazs/laravel-restrict-soft-deletes

Usage

  1. Use RestrictSoftDeletes in your Model you want to have restricted
  2. Add a protected attibute to your Model class listing the Eloquent relationships to be watched
  3. In case of an attempted deletion on a restricted model the trait will throw a Netpok\Database\Support\DeleteRestrictionException (HTTP 403)

Example

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Netpok\Database\Support\RestrictSoftDeletes;

class User extends Model
{
    use SoftDeletes;
    use RestrictSoftDeletes;

    /**
     * The relations restricting model deletion
     */
    protected $restrictDeletes = ['posts'];

    /**
     * Eloquent relationship (has to be defined for RestrictSoftDeletes to work!)
     */
    public function posts()
    {
        return $this->hasMany('App\Post');
    }

    ...
}

In this example a User can not be deleted while they have any Post that is not soft-deleted.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: CC-BY-SA-4.0
  • 更新时间: 2018-11-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固