Skip to content

How to do avoid using policies? #139

Answered by lorisleiva
armen9494 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there 👋

If your application needs to keep track of authorisation in multiple places, including passing on that information to the frontend, then I would recommend using a Policy. Policies are a good pattern and put all your security concerns in one file for a given model, I wouldn't fight them if your application could benefit from them. You can then make your authorize methods delegate to the Policies directly like so.

use Illuminate\Support\Facades\Gate;

public function authorize(ActionRequest $request): bool
{
    return Gate::check('delete', $request->project);
}

And also use them anywhere else in your code:

public function edit(Project $project)
{
    ......
    return [
        'd…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by armen9494
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #138 on October 17, 2021 09:27.