laravel blade - how to hide the display of an html element for specific routes
laravel blade - how to hide the display of an html element for specific routes
folks!
I am using Laravel 5.6 with Hyn Laravel-Tenancy Installed.
I have a main menu that is the same for all tenants (subdomains), however, for one or another specific tenant (subdomain), I would like some items to be displayed from that main menu, but for all other tenants, these menu items not visible and also inaccessible, even if called by the url.
On the Blade I used a "@if route::has", but even limited that route to a specific subdomain, this route is available for all other subdomains, so that @if receives as true and ends up displaying the menu item.
I'm not finding a simple solution, could create a helper that identifies the url and if it is from a specific subdomain, would display the item and for the other subdomains would not be displayed, but "I guess" that it should have a native form using Blade along with "routesweb" to achieve this result.
Thanks!!!
@if(app(HynTenancyEnvironment::class)->tenant() == 'specialTenant') //show nav @endif
laravel.com/docs/5.6/authorization wite a gate to determine if they can view the links and then you can simply do @can('gate-name') display links @endcan
– rchatburn
Aug 31 at 16:14
1 Answer
1
use gate and can in laravl
in authserviceprovider create a gate like that:
$gate->define('see-menu',function()
//check domains or rules or every thing that you need to check to obtain access
//return true if user have access and false if not access
);
and in you view use can to check see-menu
@can('see-menu')
//your code
<li class="devider"></li>.......
@endcan
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You'll likely need to code up a helper function yourself here, as Blade will need some way of knowing what tenants to show this for. It looks like that package has a way of identifying the current tenant, which you could do in the blade file and pass back to your helper. E.g.
@if(app(HynTenancyEnvironment::class)->tenant() == 'specialTenant') //show nav @endif
laravel-tenancy.com/docs/hyn/5.2/…– Rich
Aug 30 at 19:50