juliomotol / laravel-admin-panel
This is my package laravel-admin-panel
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 1
pkg:composer/juliomotol/laravel-admin-panel
Requires
- php: ^8.1
- illuminate/console: ^9.0
- illuminate/contracts: ^9.0
- illuminate/support: ^9.0
- illuminate/view: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2023-08-03 09:24:42 UTC
README
A simple CoreUI admin panel template with sidebar navigation management.
Installation
You can install the package via composer:
composer require juliomotol/laravel-admin-panel
After installing, publish its assets using the admin-panel:install Artisan command.
php artisan admin-panel:install
Add a
--no-assetsoption if you want to build your own assets.
If you prefer to use the provided assets you should publish the assets with:
@php artisan vendor:publish --tag=admin-panel-assets
To keep the assets up-to-date and avoid issues in future updates, we highly recommend adding the command to the post-autoload-dump scripts in your composer.json file:
"scripts": { "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force", "@php artisan vendor:publish --tag=admin-panel-assets --ansi --force" ] }
Include the assets by adding the following Blade directives in the head tag, and before the end body tag in your template.
<html> <head> ... @adminPanelStyle </head> <body> ... @adminPanelScript </body> </html>
You can publish the config file with:
php artisan vendor:publish --tag="laravel-admin-panel-config"
This is the contents of the published config file:
return [
];
Optionally, you can publish the views using
php artisan vendor:publish --tag="laravel-admin-panel-views"
Usage
Adding the component to your template
In your template:
<x-admin-panel-component> <!-- your mark up --> </x-admin-panel-component>
You can add your own brand logos to the sidebar and header (only visible in mobile view) with:
<x-admin-panel-component> <x-slot:sidebarBrand :src="asset('logo.png')"></x-slot> <x-slot:headerBrand :src="asset('logo.png')"></x-slot> <!-- your mark up --> </x-admin-panel-component>
Any additional attributes will be passed to their respective
<img>tags.
The
<x-slot:headerBrand>slot can also accept anhrefattribute that will be passed to the<a>tag enclosing the logo.
You can add your own footer with:
<x-admin-panel-component> <!-- your mark up --> <x-slot:footer> <div> Copyright © {{ date('Y') }} </div> </x-slot> </x-admin-panel-component>
Sidebar & Account Navigation
In your AdminPanelServiceProvider, you can build your sidebar and account dropdown navigation by:
class AdminPanelServiceProvider extends AdminPanelApplicationServiceProvider { protected function build(AdminPanelManager $adminPanel): void { $adminPanel->sidebar() ->addItem('Dashboard', 'admin.dashboard') ->addGroup( 'Access', fn (NavigationGroup $group) => $group ->addItem( 'Users', callback: fn (NavigationItem $item) => $item ->additem('Admin', 'admin.users.admins.index') ->additem('Clients', 'admin.users.clients.index') ) ->addItem('Roles', 'admin.roles') ); $adminPanel->account() ->addItem('My Profile', 'admin.my-profile.index'); ->addItem('Logout', 'auth.logout'); $adminPanel->setAccountAvatarResolver(fn () => Auth::user()->avatar()) } }
Adding Navigation Items
You can further customize the navigation item with by passing a closure:
$adminPanel->sidebar() /** * @param string $title * @param ?string $route Can either be a named route or a url * @param array $parameters The parameters for the named route * @param \Closure $callback */ ->addItem('Inquiries', 'admin.inquiries', callback: fn (NavigationItem $item) => ...)
The
NavigationItemuses Laravel'sConditionabletrait. You can usewhen()andunless()methods to customize it.
You can add an icon class with:
$adminPanel->sidebar() ->addItem( 'Inquiries', 'admin.inquiries', callback: fn (NavigationItem $item) =>$item->withIconClass('cil-notes') );
The assets comes bundled with CoreUI Icons.
NOTE: The icon will not be shown in the account dropdown.
You can add a badge with:
$adminPanel->sidebar() ->addItem( 'Inquiries', 'admin.inquiries', callback: fn (NavigationItem $item) =>$item->withBadge( /** * @param string|\Closure $title * @param BadgeStyle $style */ Badge::make( fn() => Inquiries::isUnread()->count(), // Also accepts a string BadgeStyle::SUCCESS ) ) );
Available badge styles are:
BadgeStyle::PRIMARY BadgeStyle::SECONDARY BadgeStyle::INFO BadgeStyle::SUCCESS BadgeStyle::WARNING BadgeStyle::ERROR
You can also add a dropdown with:
$adminPanel->sidebar() ->addItem( 'Inquiries', 'admin.inquiries', callback: fn (NavigationItem $item) =>$item->addItem(...) );
NOTE: The dropdown will only be shown in the sidebar. No icons will be show to the dropdown items either.
Adding Navigation Groups
You can add items within the navigation group with by passing a closure:
$adminPanel->sidebar() /** * @param string $title The title shown for this navigation group * @param \Closure $callback A closure to modify */ ->addGroup( 'CMS', fn (NavigationGroup $group) => $group->addItem('Pages', 'admin.pages') ->addItem('Blocks', 'admin.blocks') ->addItem('Meta', 'admin.meta') );
The
NavigationGroupuses Laravel'sConditionabletrait. You can usewhen()andunless()methods to conditionaly add items.
Setting an Account Avatar
You can display a different account avatar with:
$adminPanel->setAccountAvatarResolver(fn () => Auth::user()->avatar());
Build your own assets
A set sensible default assets is provided to you, but if you want to implement your own build steps, during admin-panel:install, add a --no-assets option:
php artisan admin-panel:install --no-assets
Then install the asset deps via NPM:
npm install @coreui/coreui @coreui/icons @coreui/utils simplebar --save-dev
See the /assets as a starting ground for your assets.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.