定制 iatstuti/laravel-owns-models 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

iatstuti/laravel-owns-models

Composer 安装命令:

composer require iatstuti/laravel-owns-models

包简介

A simple trait to use with models to check whether they own other models.

README 文档

README

v1.0.0

Travis Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads License

This is a small trait that allows you to determine whether the using model owns some other model within your application. Using the trait makes it trivial to perform authorisation checks to determine whether some user has access to another model, for example.

Installation

This trait is installed via Composer. To install, simply add it to your composer.json file:

{
    "require": {
        "iatstuti/laravel-owns-models": "~1.0"
    }
}

Then run composer to update your dependencies:

$ composer update

In order to use this trait, import it in your Eloquent model. You can then use either the owns or doesntOwn method to determine if some model owns another, based on either the default or explicit keys for each.

<?php

use Iatstuti\Database\Support\OwnsModels;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use OwnsModels;
}

class Post extends Model
{
}

$user = User::find($user_id);
$post = Post::find($post_id);

if ($user->owns($post)) {
    // Continue execution
}

if ($user->doesntOwn($post)) {
    // Generate some authorisation error
}

Prior to Laravel 5.2, the primary key of the model was returned as a string. As a result, this package does loose comparisons by default, to provide maximum version compatibility.

If you want to perform strict comparisons in older versions, you can add your primary key field to the $casts property as an integer and call the owns method with additional parameters:

$user->owns($post, null, true);
$user->doesntOwn($post, null, true);

At the first release of this package, I believe people are more likely to change the second ($foreignKey) parameter than explicitly set the third ($strict) parameter. If you think otherwise, or have a better way of handling this, please get in touch!

Support

If you are having general issues with this package, feel free to contact me on Twitter.

If you believe you have found an issue, please report it using the GitHub issue tracker, or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!

统计信息

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

GitHub 信息

  • Stars: 14
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固