orchidsoftware / platform

Orchid is a @laravel package that allows for rapid application development of back-office applications, admin/user panels, and dashboards.
https://orchid.software
MIT License
4.26k stars 631 forks source link

Test Orchid platform access permission from the laravel application #2651

Closed Cyrille37 closed 12 months ago

Cyrille37 commented 1 year ago

Hello Thanks a lot for this great tool <3

Orchid platform is at /admin and I want to display or not a link to this in the laravel application, based on permission or gate or ???.

I tried in an application blade view different authorization strings like Auth::user()->can('platform') and 'platform.index' and 'platform.main' but none work.

Is exist a string that Laravel Authorization can test ? I did not find in the documentation. Perhaps the solution can be added in configuration section.

Thanks & cheers :-)

Cyrille37 commented 1 year ago

I also try @if( Auth::guard( config('platform.guard') )->user()->can('platform.index')) but it say Auth guard [platform.guard] is not defined.

Cyrille37 commented 1 year ago

Ok, I found the solution to make a link to Orchid platform from Application menu :

@if( Auth::user()->hasAccess('platform.index'))
  <x-nav-link href="{{ route('platform.index') }}" :active="request()->routeIs('platform.index')">
    {{ __('Admin') }}
  </x-nav-link>
@endif

Method hasAccess() is defined in Trait Orchid\Access\UserAccess that is used in Orchid\Platform\Models\User that our application's User extends.

So simple :-)