2018-06-20 05:06:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Admin\Providers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
2018-07-05 07:58:26 +00:00
|
|
|
use Webkul\Admin\Providers\EventServiceProvider;
|
2018-10-17 07:40:08 +00:00
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler;
|
|
|
|
|
use Webkul\Admin\Exceptions\Handler;
|
2018-12-14 08:26:05 +00:00
|
|
|
use Webkul\Core\Tree;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Admin service provider
|
|
|
|
|
*
|
|
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
2018-06-20 05:06:27 +00:00
|
|
|
class AdminServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
|
|
|
|
include __DIR__ . '/../Http/routes.php';
|
|
|
|
|
|
2018-07-11 05:41:27 +00:00
|
|
|
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'admin');
|
|
|
|
|
|
2018-06-20 05:06:27 +00:00
|
|
|
$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->loadViewsFrom(__DIR__ . '/../Resources/views', 'admin');
|
|
|
|
|
|
2018-06-25 11:00:42 +00:00
|
|
|
$this->composeView();
|
|
|
|
|
|
2018-12-20 10:54:30 +00:00
|
|
|
$this->registerACL();
|
|
|
|
|
|
2018-07-05 07:58:26 +00:00
|
|
|
$this->app->register(EventServiceProvider::class);
|
2018-10-17 07:40:08 +00:00
|
|
|
|
|
|
|
|
$this->app->bind(
|
|
|
|
|
ExceptionHandler::class,
|
|
|
|
|
Handler::class
|
|
|
|
|
);
|
2018-06-25 11:00:42 +00:00
|
|
|
}
|
2018-12-12 09:39:20 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register services.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function register()
|
|
|
|
|
{
|
|
|
|
|
$this->registerConfig();
|
|
|
|
|
}
|
2018-06-25 11:00:42 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bind the the data to the views
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function composeView()
|
|
|
|
|
{
|
2018-07-12 07:12:48 +00:00
|
|
|
view()->composer(['admin::layouts.nav-left', 'admin::layouts.nav-aside', 'admin::layouts.tabs'], function ($view) {
|
2018-12-14 08:26:05 +00:00
|
|
|
$tree = Tree::create();
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
foreach (config('menu.admin') as $item) {
|
2018-12-14 08:26:05 +00:00
|
|
|
if (bouncer()->hasPermission($item['key'])) {
|
|
|
|
|
$tree->add($item, 'menu');
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-25 11:00:42 +00:00
|
|
|
|
2018-12-14 08:26:05 +00:00
|
|
|
$tree->items = core()->sortItems($tree->items);
|
2018-12-12 10:56:20 +00:00
|
|
|
|
2018-12-14 08:26:05 +00:00
|
|
|
$view->with('menu', $tree);
|
2018-12-13 10:58:28 +00:00
|
|
|
});
|
2018-07-02 09:29:27 +00:00
|
|
|
|
2018-12-14 08:26:05 +00:00
|
|
|
view()->composer(['admin::users.roles.create', 'admin::users.roles.edit'], function ($view) {
|
2018-12-20 10:54:30 +00:00
|
|
|
$view->with('acl', $this->createACL());
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-12-14 08:26:05 +00:00
|
|
|
|
2018-12-20 10:54:30 +00:00
|
|
|
/**
|
|
|
|
|
* Registers acl to entire application
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function registerACL()
|
|
|
|
|
{
|
|
|
|
|
$this->app->singleton('acl', function () {
|
|
|
|
|
return $this->createACL();
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-12-14 08:26:05 +00:00
|
|
|
|
2018-12-20 10:54:30 +00:00
|
|
|
/**
|
|
|
|
|
* Create acl tree
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function createACL()
|
|
|
|
|
{
|
|
|
|
|
static $tree;
|
2018-12-14 08:26:05 +00:00
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if ($tree)
|
2018-12-20 10:54:30 +00:00
|
|
|
return $tree;
|
|
|
|
|
|
|
|
|
|
$tree = Tree::create();
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
foreach (config('acl') as $item) {
|
2018-12-20 10:54:30 +00:00
|
|
|
$tree->add($item, 'acl');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tree->items = core()->sortItems($tree->items);
|
|
|
|
|
|
|
|
|
|
return $tree;
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
2018-12-12 09:39:20 +00:00
|
|
|
|
2018-06-20 05:06:27 +00:00
|
|
|
/**
|
2018-12-12 09:39:20 +00:00
|
|
|
* Register package config.
|
2018-06-20 05:06:27 +00:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2018-12-12 09:39:20 +00:00
|
|
|
protected function registerConfig()
|
2018-06-20 05:06:27 +00:00
|
|
|
{
|
2018-12-12 09:39:20 +00:00
|
|
|
$this->mergeConfigFrom(
|
|
|
|
|
dirname(__DIR__) . '/Config/menu.php', 'menu.admin'
|
|
|
|
|
);
|
2018-06-20 05:06:27 +00:00
|
|
|
|
2018-12-12 09:39:20 +00:00
|
|
|
$this->mergeConfigFrom(
|
|
|
|
|
dirname(__DIR__) . '/Config/acl.php', 'acl'
|
|
|
|
|
);
|
2018-06-20 05:06:27 +00:00
|
|
|
}
|
2018-12-12 09:39:20 +00:00
|
|
|
}
|