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

[5.7] Show exception message on 403 when available #26356

Merged
merged 1 commit into from
Nov 2, 2018
Merged

[5.7] Show exception message on 403 when available #26356

merged 1 commit into from
Nov 2, 2018

Conversation

ankurk91
Copy link
Contributor

@ankurk91 ankurk91 commented Nov 2, 2018

Hi,

When throwing custom AuthorizationException("custom message") exception; the 403 page should show the message set by exception instead of default one.

One of most common place to send custom message from policies, for example

<?php

namespace App\Policies;

use App\Models\Job;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class JobPolicy
{
    use HandlesAuthorization;

    /**
     * Determine if the given user can accept job.
     *
     * @param  \App\Models\User $authUser
     * @param  \App\Models\Job $job
     * @throws \Exception
     * @return bool
     */
    public function accept(User $authUser, Job $job)
    {
        if ($job->expired) {
            return $this->deny("The requested Job has been expired.");
        }

        return true;
    }
}

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.

2 participants