Navigation
Larasell allows you to add items to the sidebar navigation of the admin panel.
Adding items
First, create a routes/admin.php file, if it does not exist.
Use the Navigation facade inside routes/admin.php to add an item to the sidebar. Each item needs a label, a route and an icon. The icon is an Icon enum case or a Remix icon name such as 'sticky-note':
1use Larasell\Admin\Enums\Icon;
2use Larasell\Admin\Facades\Navigation;
3
4Route::get('notes', NotesController::class)->name('notes');
5
6Navigation::add('Notes', 'larasell.admin.notes', Icon::StickyNote);The route group inside routes/admin.php prefixes route names with
larasell.admin., so notes becomes larasell.admin.notes. Pass the full
route name to the facade.
Adding table pages
When an item links to a table, you can register the route and
the item in one call with the index method instead:
1use App\Tables\ProductReviewTable;
2use Larasell\Admin\Enums\Icon;
3use Larasell\Admin\Facades\Navigation;
4
5Navigation::index(
6 'Reviews',
7 'reviews',
8 ProductReviewTable::class,
9 Icon::Star,
10);It takes a label, a URI, the table class and an icon. It does the same as:
1Route::index('reviews', ProductReviewTable::class);
2
3Navigation::add('Reviews', 'larasell.admin.reviews.index', Icon::Star);The route is named after the URI, so reviews becomes larasell.admin.reviews.index.
Use that name to place other items before or after it.
Positioning items
By default, the panel appends items to the bottom of the navigation.
To control where an item appears, set an explicit position using the position method:
1Navigation::add('Notes', 'larasell.admin.notes', Icon::StickyNote)->position(500);The panel sorts items by position in ascending order.
Placing items relatively
Instead of setting a numeric position, you can place an item before or after an existing one. The
target can be the id of an existing item or a NavItem enum case:
1use Larasell\Admin\Enums\Icon;
2use Larasell\Admin\Enums\NavItem;
3use Larasell\Admin\Facades\Navigation;
4
5Navigation::add('Notes', 'larasell.admin.notes', Icon::StickyNote)->before('larasell.admin.home');
6Navigation::add('Reports', 'larasell.admin.reports', Icon::FileChart)->after(NavItem::Home);NavItem has a case for each built-in item: Home, Products, Categories, Orders,
Customers and Settings.
Nesting items
Group related pages by nesting them under another item. Use the children method to add
items under the one you just added:
1use App\Tables\ProductReviewTable;
2use Larasell\Admin\Enums\Icon;
3use Larasell\Admin\Facades\Navigation;
4use Larasell\Admin\NavigationGroup;
5
6Navigation::add('Notes', 'larasell.admin.notes', Icon::StickyNote)
7 ->children(function (NavigationGroup $notes) {
8 $notes->add('Reports', 'larasell.admin.reports', Icon::FileChart);
9
10 $notes->index(
11 'Reviews',
12 'reviews',
13 ProductReviewTable::class,
14 Icon::Star,
15 );
16 });The group has the same add and index methods as the Navigation facade.
To nest an item under an item you didn't add, like a built-in one, use the under method. It
takes the id of the parent or a NavItem case:
1use Larasell\Admin\Enums\Icon;
2use Larasell\Admin\Enums\NavItem;
3use Larasell\Admin\Facades\Navigation;
4
5Navigation::add('Team', 'larasell.admin.team', Icon::Group)
6 ->under(NavItem::Settings);Items nest one level deep, so the parent must be a top-level item.
position, before and after work on nested items too, but they only order an item among
the other children of the same parent.