60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Page;
|
|
use App\Models\Product;
|
|
use App\Services\EmployeeSyncService;
|
|
use Illuminate\Pagination\Paginator;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Infrastructure\Adapters\Repositories\EloquentProductRepository;
|
|
|
|
class ViewServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot(EloquentProductRepository $productRepository)
|
|
{
|
|
$this->setUpBladeMacros($productRepository);
|
|
|
|
if ($this->app->runningInConsole() && ! $this->app->runningUnitTests()) {
|
|
return;
|
|
}
|
|
|
|
$this->setupPaginator();
|
|
}
|
|
|
|
private function setupPaginator(): void
|
|
{
|
|
// * PAGINATOR
|
|
if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') {
|
|
Paginator::defaultView('bo.modules.pagination');
|
|
} else {
|
|
Paginator::defaultView('fo.modules.pagination');
|
|
}
|
|
|
|
// * PAGE LIST
|
|
View::composer('*', function ($view) {
|
|
$view->with('PageList', Page::getCached()
|
|
->mapWithKeys(fn ($page) => [
|
|
$page->slug->value() => $page,
|
|
]));
|
|
$view->with('EmployeeSyncService', resolve(EmployeeSyncService::class));
|
|
});
|
|
}
|
|
|
|
private function setUpBladeMacros(EloquentProductRepository $productRepository): void
|
|
{
|
|
Blade::if(
|
|
'orderable',
|
|
fn (Product $product) => $productRepository->toEntity($product)->isOrderable()
|
|
);
|
|
}
|
|
}
|