Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Update upgrade guide to include HandlesAuthorization trait change #5531

Merged
merged 1 commit into from
Oct 15, 2019
Merged

[6.x] Update upgrade guide to include HandlesAuthorization trait change #5531

merged 1 commit into from
Oct 15, 2019

Conversation

ankurk91
Copy link
Contributor

Hi,

This PR adds instructions for a change in Illuminate\Auth\Access\HandlesAuthorization trait that was introduced in this pull request.
laravel/framework#29117

Laravel 5.8 behaviour

The deny() method throws an exception and there is no need of return statement.
The return is useless here knowing that it will throw exception.

    public function update(User $user, Post $post)
    {
        if($user->role !== 'editor') {
            // works without return
            $this->deny("You must be an editor to edit a post.")
        }
        
        return $user->id === $post->user_id;
    }

Laravel 6.0 behaviour

The deny() method no longer throws an exception, developer need to add a return statement in order to make the policy work.
Without the return statement, all of the deny() calls are being ignored.

    public function update(User $user, Post $post)
    {
        if($user->role !== 'editor') {
           // need to add return
            return $this->deny("You must be an editor to edit a post.")
        }
        
        return $user->id === $post->user_id;
    }

Feel free to suggest edits.

@driesvints driesvints changed the title Update upgrade guide to include HandlesAuthorization trait change [6.x] Update upgrade guide to include HandlesAuthorization trait change Oct 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants