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!!!



routesweb.php



enter image description here





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


@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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)