sarga/packages/Webkul/Shop/src/Providers/ShopServiceProvider.php

78 lines
2.1 KiB
PHP
Raw Normal View History

2018-07-12 07:12:48 +00:00
<?php
namespace Webkul\Shop\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Event;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Blade;
use Webkul\Shop\Providers\ComposerServiceProvider;
2018-10-17 07:21:47 +00:00
use Webkul\Ui\Menu;
2018-07-12 07:12:48 +00:00
class ShopServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
include __DIR__ . '/../Http/routes.php';
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'shop');
2018-07-12 07:12:48 +00:00
$this->publishes([
2018-08-17 05:48:21 +00:00
__DIR__ . '/../../publishable/assets' => public_path('themes/default/assets'),
2018-07-12 07:12:48 +00:00
], 'public');
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'shop');
$this->app->register(ComposerServiceProvider::class);
2018-10-17 07:21:47 +00:00
$this->composeView();
$this->createCustomerMenu();
}
/**
* Bind the the data to the views
*
* @return void
*/
protected function composeView()
{
view()->composer('shop::customers.account.partials.sidemenu', function ($view) {
$menu = current(Event::fire('customer.menu.create'));
$view->with('menu', $menu);
});
2018-07-12 07:12:48 +00:00
}
/**
2018-10-17 07:21:47 +00:00
* This method fires an event for menu creation, any package can add their menu item by listening to the customer.menu.build event
2018-07-12 07:12:48 +00:00
*
* @return void
*/
2018-10-17 07:21:47 +00:00
public function createCustomerMenu()
2018-07-12 07:12:48 +00:00
{
2018-10-17 07:21:47 +00:00
Event::listen('customer.menu.create', function () {
return Menu::create(function ($menu) {
Event::fire('customer.menu.build', $menu);
});
});
Event::listen('customer.menu.build', function ($menu) {
$menu->add('profile', 'Profile', 'customer.profile.index', 1);
$menu->add('orders', 'Orders', 'customer.orders.index', 2);
$menu->add('address', 'Address', 'customer.address.index', 3);
$menu->add('reviews', 'Reviews', 'customer.reviews.index', 4);
$menu->add('wishlist', 'Wishlist', 'customer.wishlist.index', 5);
});
2018-07-12 07:12:48 +00:00
}
}