# Add menu in admin
- In your package's source directory i.e.
packages/ACME/HelloWorld/src
, create theConfig
folder and create a file namedadmin-menu.php
.
<?php
return [
[
'key' => 'helloworld',
'name' => 'Hello World',
'route' => 'helloworld.admin.index',
'sort' => 1,
'icon-class' => 'dashboard-icon',
]
];
- In this file, we provide the name of the menu, route & its icon.
Params | Description |
---|---|
key | Unique key for menu icon. |
name | Name of menu icon. |
route | Route name for your menu icon. |
sort | Sort number on which your menu icon should display. |
icon-class | Class for menu icon. |
For the route, just add the named route which specified above i.e.
helloworld.admin.index
,Route::view('/admin/hello-world', 'helloworld::admin.index')->name('helloworld.admin.index');
After that, we need to merge this
menu.php
folder with a core menu file. For this, we use the methodmergeConfigFrom()
in the register method of the service provider.<?php namespace ACME\HelloWorld\Providers; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; class HelloWorldServiceProvider extends ServiceProvider { /** * Register services. * * @return void */ public function register() { $this->mergeConfigFrom( dirname(__DIR__) . '/Config/admin-menu.php', 'menu.admin' ); } }
Run this command i.e.
php artisan optimize
.Now, the menu will display in the admin panel. You can change the icon according to your needs.