-
-
Notifications
You must be signed in to change notification settings - Fork 2
Usage
-
for language switcher.
SimpleMenu::getUrl($langCode)
{{ SimpleMenu::getUrl('en') }}
-
for resolving routes & params for the menu list.
SimpleMenu::getRoute($pageRouteName, $params = null)
@php // same as "route($page->route_name)" SimpleMenu::getRoute($page->route_name); // resolve routes with params SimpleMenu::getRoute($page->route_name, [ 'about' => ['name'=>'hello'], 'contact-us' => ['name'=>'there'], ]); @endphp // to resolve url <a href="{{ SimpleMenu::routeUrl() }}">{{ $page->title }}</a> // to style the active link <a href="{{ SimpleMenu::routeUrl() }}" class="{{ SimpleMenu::isActiveRoute() ? 'is-active' : '' }}"> {{ $page->title }} </a>
-
in case you have a route located in more than one place
ex.(top menu, footer menu, breadcrumb)
or you simply need a centralized place to add the above code, then1- add
@include('SimpleMenu::menu.partials.r_params')
to your views. example2- because this is a partial, you can send any params just like normal docs
-
-
for automatic menu list render.
SimpleMenu::render($pages, $menuClasses = null, $routeParams = null)
-
here is where
$PAGES
come from
// the $menuClasses could be // "null" for not including any classes // "config" for using the ones under "simpleMenu.listClasses" // or added manually as below {!! SimpleMenu::render ( $PAGES, ['ul' => 'menu-list', 'li' => 'list-item', 'a' => 'is-active'], [ 'contact-us' => ['name'=>'test'] ] ) !!}
-
here is where
-
for retrieving page params
like (template, title, body, desc, meta, cover, breadCrumb, middlewares, roles, permissions)
useextract(SimpleMenu::getRouteData('the-route-name'));
if you followed the naming convention as in Good Practice and you are inside a page method, you can instead use
extract(SimpleMenu::getRouteData(kebab_case('theCurrentMethodName')));
method name format output = route_name contactUs kebab_case('contactUs') contact-us also to make sure you get a clean route middleware, combine/merge the middlewares, roles, permissions through
array_filter(array_flatten([$middlewares, $roles, $permissions]));
- the package automatically register 4 middlewares to handle all the routes but incase you want to use them anywhere else, they are
localizationRedirect
localeSessionRedirect
role:roleName
perm:permName
-
in case you are using some package that caches the response and you need to invalidate the cache when any of the package CRUD operations is fired, you can listen to
sm-menus.cleared
sm-pages.cleared
sm-users.cleared
sm-perms.cleared
or in one go through
Event::listen('sm-*', function () { // do something });
all the models the package use are cached, which you can access through
- pages:
app('cache')->tags('sm')->get('pages')
- menus:
app('cache')->tags('sm')->get('menus')
- users:
app('cache')->get('sm-users')