cybercog / laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.
https://komarev.com/sources/laravel-ownership
MIT License
89 stars 16 forks source link

OwnedOrFail #12

Closed blendsoft closed 7 years ago

blendsoft commented 7 years ago

Could you add method(s) throwing exception when not owner ?

antonkomarev commented 7 years ago

@blendsoft Throw exception when model don't have any owners or when exact user not an owner of it?

Could you provide usage example, please?

antonkomarev commented 7 years ago

You can use default firstOrFail method mixed with whereOwnedBy scope:

Article::whereKey($articleId)->whereOwnedBy($user)->firstOrFail();

Does this help?

antonkomarev commented 7 years ago

Closing this issue. Feel free to continue conversation if solution proposed above didn't help.