2018-06-20 05:06:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Admin\Providers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
use Illuminate\Support\Facades\Event;
|
2018-06-25 11:00:42 +00:00
|
|
|
use Illuminate\Support\Facades\Blade;
|
|
|
|
|
use Webkul\Ui\Menu;
|
2018-06-20 05:06:27 +00:00
|
|
|
|
|
|
|
|
class AdminServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
|
|
|
|
include __DIR__ . '/../Http/routes.php';
|
|
|
|
|
|
|
|
|
|
$this->publishes([
|
2018-06-20 08:22:48 +00:00
|
|
|
__DIR__ . '/../../publishable/assets' => public_path('vendor/webkul/admin/assets'),
|
2018-06-20 05:06:27 +00:00
|
|
|
], 'public');
|
|
|
|
|
|
|
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../Database/migrations');
|
|
|
|
|
|
|
|
|
|
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'admin');
|
|
|
|
|
|
|
|
|
|
$this->createAdminMenu();
|
2018-06-25 11:00:42 +00:00
|
|
|
|
|
|
|
|
$this->composeView();
|
|
|
|
|
|
|
|
|
|
Blade::directive('continue', function() { return "<?php continue; ?>"; });
|
|
|
|
|
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method fires an event for menu creation, any package can add their menu item by listening to the admin.menu.build event
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function createAdminMenu()
|
|
|
|
|
{
|
|
|
|
|
Event::listen('admin.menu.create', function() {
|
|
|
|
|
return Menu::create(function($menu) {
|
|
|
|
|
Event::fire('admin.menu.build', $menu);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Event::listen('admin.menu.build', function($menu) {
|
2018-06-25 11:00:42 +00:00
|
|
|
$menu->add('dashboard', 'Dashboard', route('admin.dashboard.index'), 1, 'icon-dashboard');
|
|
|
|
|
|
2018-06-26 12:55:09 +00:00
|
|
|
$menu->add('configuration', 'Configure', route('admin.account.edit'), 6, 'icon-configuration');
|
|
|
|
|
|
|
|
|
|
$menu->add('configuration.account', 'My Account', route('admin.account.edit'), 1, '');
|
2018-06-25 11:00:42 +00:00
|
|
|
|
|
|
|
|
$menu->add('settings', 'Settings', '', 6, 'icon-settings');
|
|
|
|
|
|
|
|
|
|
$menu->add('settings.users', 'Users', route('admin.users.index'), 1, '');
|
|
|
|
|
|
|
|
|
|
$menu->add('settings.roles', 'Roles', route('admin.permissions.index'), 2, '');
|
2018-06-26 12:55:09 +00:00
|
|
|
|
2018-06-25 11:00:42 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bind the the data to the views
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function composeView()
|
|
|
|
|
{
|
|
|
|
|
view()->composer('admin::layouts.nav-left', function($view) {
|
|
|
|
|
$menu = current(Event::fire('admin.menu.create'));
|
|
|
|
|
$view->with('menu', $menu);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
view()->composer('admin::layouts.nav-aside', function($view) {
|
2018-06-26 12:55:09 +00:00
|
|
|
$parentMenu = current(Event::fire('admin.menu.create'));
|
|
|
|
|
$menu = [];
|
|
|
|
|
foreach ($parentMenu->items as $item) {
|
|
|
|
|
$currentKey = current(explode('.', $parentMenu->currentKey));
|
2018-06-25 11:00:42 +00:00
|
|
|
if($item['key'] != $currentKey)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
$menu = [
|
2018-06-26 12:55:09 +00:00
|
|
|
'items' => $parentMenu->sortItems($item['children']),
|
|
|
|
|
'current' => $parentMenu->current,
|
|
|
|
|
'currentKey' => $parentMenu->currentKey
|
2018-06-25 11:00:42 +00:00
|
|
|
];
|
|
|
|
|
}
|
2018-06-26 12:55:09 +00:00
|
|
|
|
|
|
|
|
$view->with('menu', $menu);
|
2018-06-20 05:06:27 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function register()
|
|
|
|
|
{
|
|
|
|
|
$this->mergeConfigFrom(
|
|
|
|
|
__DIR__ . '/../Config/auth.php', 'auth'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Merge the given configuration with the existing configuration.
|
|
|
|
|
*
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function mergeConfigFrom($path, $key)
|
|
|
|
|
{
|
|
|
|
|
$config = $this->app['config']->get($key, []);
|
|
|
|
|
|
|
|
|
|
$this->app['config']->set($key, array_merge($config, require $path));
|
|
|
|
|
}
|
|
|
|
|
}
|