thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.8k stars 2.67k forks source link

symfony error after upgrade to 1.1 #3081

Closed husseinelhussein closed 6 years ago

husseinelhussein commented 6 years ago

Description:

first of all thanks for this library it's really amazing work and saved me a lot of time. i tried to edit bread but got missing permission error, so i tried to add browse_bread key to permissions table now when i visit /admin/bread//edit i see this error: Type error: Argument 1 passed to Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException::__construct() must be of the type string, null given, called in vendor\tcg\voyager\src\Voyager.php on line 245

Steps To Reproduce:

  1. add permission with key browse_bread or browse_hooks
  2. go to /admin/bread/<any_table>/edit or /admin/hooks
MrCrayon commented 6 years ago

I think Voyager 1.0 only supported up to Laravel 5.5 so that means that you also upgraded Laravel version and you need to check: https://laravel.com/docs/5.6/upgrade I think your problem is in the Trusted Proxies section but better you check all doc.

fletch3555 commented 6 years ago

@MrCrayon, did you reply to the correct issue....? You mention Voyager 1.0, Laravel 5.5, and TrustedProxies, but the issue mentions Voyager 1.1, Laravel 5.6, and UnauthorizedHttpException (a permissions error). Your comment doesn't seem relevant at all

MrCrayon commented 6 years ago

@fletch3555 yes my reply was for this issue. In the title he said he upgraded to Voyager 1.1 meaning he had before Voyager 1.0. That also means, if I'm not mistaken, that he was using Laravel 5.5. That's why I suggested to check Laravel upgrade guide too.

Also googling for his error I found this one: https://github.com/laravel/framework/issues/23058

Edit: It's not the same error but that led me to the upgrade issue.

MrCrayon commented 6 years ago

Digging a bit more on the specific error looks like null is not anymore valid as argument for the exception:

    /** @deprecated */
    public function canOrFail($permission)
    {
        if (!$this->can($permission)) {
            throw new UnauthorizedHttpException(null);
        }

        return true;
    }

That method is deprecated but is still used in VoyagerBreadContoller, VoyagerCompassController, VoyagerMediaController and VoyagerSettingsController.

Quick fix for @husseinelhussein you need to enable browse_bread permission to your user role after you add it to db.

P.S. Checking Laravel upgrade guide is still advised.

husseinelhussein commented 6 years ago

@MrCrayon i already saw that error too, and i fixed it by editing: App\Http\Middleware\TrustProxies.php anyway, solution for the UnauthorizedHttpException was simply adding relations between the permission and the role

  1. added new row in permission_role table and pointed the required permission to the role
MrCrayon commented 6 years ago

@husseinelhussein yes that solves the problem but Voyager code still needs to be fixed to not use null and also replace use of deprecated methods.

@fletch3555 what would be the correct replacement for this?

Voyager::canOrFail('browse_database');
github-actions[bot] commented 4 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.