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!
tmyers273/laravel-ownership 适用场景与选型建议
tmyers273/laravel-ownership 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tmyers273/laravel-ownership 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tmyers273/laravel-ownership 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-07-06