定制 tmyers273/laravel-ownership 二次开发

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

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

tmyers273/laravel-ownership

Composer 安装命令:

composer require tmyers273/laravel-ownership

包简介

Allows ownership verification on route model binding

README 文档

README

A simple package to do Model ownership checks automatically via Laravel's Route Model Binding.

What's it do?

// Let's whip up a few Users and a Post to demonstrate
$owner = factory(User::class)->create();
$post = factory(Post::class)->create([
    'user_id' => $owner->id
]);

$otherUser = factory(User::class)->create();
$adminUser = factory(USer::class)->create([
    'is_admin' => true
]);
// This will be a successful call, since $owner owns the $post
$this->be($owner);
$this->json('PATCH', '/post/' . $post->id, [
    'title' => 'Edited by Owner'
]);
// This will fail, since $otherUser does not own the $post
$this->be($otherUser);
$this->json('PATCH', '/post/' . $post->id, [
    'title' => 'Edited by Owner'
]);
// This will be a successful call, since $adminUser can override the ownership check (by default)
$this->be($adminUser);
$this->json('PATCH', '/post/' . $post->id, [
    'title' => 'Edited by Owner'
]);
// This will fail, since 12345 is a made up Post id
$this->be($owner);
$this->json('PATCH', '/post/12345', [
    'title' => 'Edited by Owner'
]);

Installation

composer require tmyers273/laravel-ownership

php artisan vendor:publish --tag=laravel-ownership-config --tag=laravel-ownership-trait

Add OwnsModels trait to your User model

use App\Traits\OwnsModels;

class User extends Authenticatable
{
    use OwnsModels;
}

Add OwnedByUser to each model you want to validate ownership on.

use TMyers273\Ownership\OwnedByUser;

class Post extends Model
{
    use OwnedByUser;
}

Modify the isAdmin and owns methods on the OwnsModels trait to fit your needs!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-07-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固