2026-07-06 12:52:52 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2026-07-08 14:55:18 +02:00
|
|
|
use App\Contracts\Directories\ProductDirectory;
|
2026-07-08 18:16:46 +02:00
|
|
|
use App\Contracts\Directories\RecipeDirectory;
|
2026-07-08 14:55:18 +02:00
|
|
|
use App\Directories\EloquentProductDirectory;
|
2026-07-08 18:16:46 +02:00
|
|
|
use App\Directories\EloquentRecipeDirectory;
|
2026-10-16 12:07:08 +02:00
|
|
|
use App\Enums\Contact\ActivitySectorEnum;
|
|
|
|
|
use App\Enums\Contact\ObjectEnum;
|
2026-07-06 12:52:52 +02:00
|
|
|
use App\Services\AdminAuthService;
|
2026-07-08 14:55:18 +02:00
|
|
|
use Domain\Models\ValueObjects\Pagination;
|
2026-10-16 12:07:08 +02:00
|
|
|
use Domain\Models\ValueObjects\Products\BreedingMethod;
|
|
|
|
|
use Domain\Models\ValueObjects\Products\Business;
|
|
|
|
|
use Domain\Models\ValueObjects\Products\ProductCategory;
|
|
|
|
|
use Domain\Models\ValueObjects\Products\ProductFormat;
|
|
|
|
|
use Domain\Models\ValueObjects\Products\Technology;
|
|
|
|
|
use Domain\Models\ValueObjects\Recipes\ConsumptionTime;
|
|
|
|
|
use Domain\Models\ValueObjects\Recipes\Inspiration;
|
|
|
|
|
use Domain\Models\ValueObjects\Recipes\Season;
|
2026-07-08 14:55:18 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-07-06 12:52:52 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2026-07-08 14:55:18 +02:00
|
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
|
use Illuminate\Support\Facades\Request;
|
2026-10-16 12:07:08 +02:00
|
|
|
use Illuminate\Support\Facades\Schema;
|
2026-07-08 14:55:18 +02:00
|
|
|
use Illuminate\Support\Facades\URL;
|
|
|
|
|
use Illuminate\Support\Facades\Vite;
|
2026-07-06 12:52:52 +02:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2026-10-16 12:07:08 +02:00
|
|
|
use Uwil\LaravelBackend\Support\ModelListRegistry;
|
|
|
|
|
use Uwil\LaravelCommon\Support\InertiaSharedRegistry;
|
|
|
|
|
use Uwil\LaravelDynamicPages\Enums\PageStatusEnum;
|
|
|
|
|
use Uwil\LaravelDynamicPages\Models\DynamicPage;
|
2026-07-06 12:52:52 +02:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
$this->app->singleton(
|
|
|
|
|
AdminAuthService::class,
|
|
|
|
|
function () {
|
|
|
|
|
$guard = Auth::guard('backend');
|
2026-07-08 14:55:18 +02:00
|
|
|
|
2026-07-06 12:52:52 +02:00
|
|
|
return new AdminAuthService($guard);
|
|
|
|
|
}
|
|
|
|
|
);
|
2026-07-08 14:55:18 +02:00
|
|
|
$this->app->singleton(
|
|
|
|
|
ProductDirectory::class,
|
|
|
|
|
fn () => new EloquentProductDirectory()
|
|
|
|
|
);
|
2026-07-08 18:16:46 +02:00
|
|
|
$this->app->singleton(
|
|
|
|
|
RecipeDirectory::class,
|
|
|
|
|
fn () => new EloquentRecipeDirectory()
|
|
|
|
|
);
|
2026-07-08 14:55:18 +02:00
|
|
|
|
|
|
|
|
$this->requestMacro();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
$this->dateSetup();
|
|
|
|
|
$this->laravelGlobalSetup();
|
2026-10-16 12:07:08 +02:00
|
|
|
$this->registerSharedInertiaProps();
|
|
|
|
|
$this->registerModelsInBackendRegistry();
|
2026-07-08 14:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function laravelGlobalSetup(): void
|
|
|
|
|
{
|
|
|
|
|
Model::shouldBeStrict(app()->environment('local'));
|
|
|
|
|
|
|
|
|
|
Vite::useCspNonce();
|
|
|
|
|
|
|
|
|
|
URL::forceScheme('https');
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-16 12:07:08 +02:00
|
|
|
private function registerSharedInertiaProps(): void
|
|
|
|
|
{
|
|
|
|
|
InertiaSharedRegistry::add('dynamicPages', function (): array {
|
|
|
|
|
if (! Schema::hasTable('dynamic_pages')) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dynamicPageModels = DynamicPage::getModelsCached()
|
|
|
|
|
->where('status', PageStatusEnum::published);
|
|
|
|
|
|
|
|
|
|
$dynamicPages = [];
|
|
|
|
|
foreach ($dynamicPageModels as $dynamicPageModel) {
|
|
|
|
|
$pascalCase = str_replace(' ', '', ucwords(str_replace('-', ' ', $dynamicPageModel->id_key)));
|
|
|
|
|
$dynamicPages["page{$pascalCase}"] = $dynamicPageModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dynamicPages;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
InertiaSharedRegistry::add('activitySectorEnum', fn () => ActivitySectorEnum::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('objectEnum', fn () => ObjectEnum::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('breedingMethodEnum', fn () => BreedingMethod::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('businessEnum', fn () => Business::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('productCategoryEnum', fn () => ProductCategory::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('productFormatEnum', fn () => ProductFormat::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('technologyEnum', fn () => Technology::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('consumptionTimeEnum', fn () => ConsumptionTime::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('inspirationEnum', fn () => Inspiration::toArray());
|
|
|
|
|
InertiaSharedRegistry::add('seasonEnum', fn () => Season::toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function registerModelsInBackendRegistry(): void
|
|
|
|
|
{
|
|
|
|
|
ModelListRegistry::add(
|
|
|
|
|
2,
|
|
|
|
|
'products',
|
|
|
|
|
trans_choice('models.classes.product', 1),
|
|
|
|
|
'name',
|
|
|
|
|
);
|
|
|
|
|
ModelListRegistry::add(
|
|
|
|
|
3,
|
|
|
|
|
'recipes',
|
|
|
|
|
trans_choice('models.classes.recipe', 1),
|
|
|
|
|
'name',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-08 14:55:18 +02:00
|
|
|
private function dateSetup(): void
|
|
|
|
|
{
|
|
|
|
|
foreach ([\LC_TIME, \LC_MESSAGES, \LC_COLLATE, \LC_CTYPE, \LC_MONETARY] as $constant) {
|
|
|
|
|
setlocale(
|
|
|
|
|
$constant,
|
|
|
|
|
sprintf(
|
|
|
|
|
'%s_%s.UTF-8',
|
|
|
|
|
Config::string('app.locale'),
|
|
|
|
|
strtoupper(Config::string('app.locale'))
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
Date::setLocale(Config::string('app.locale'));
|
|
|
|
|
Date::setFallbackLocale(Config::string('app.fallback_locale'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function requestMacro(): void
|
|
|
|
|
{
|
|
|
|
|
Request::macro('pagination', function (int $defaultPageSize = 25): Pagination {
|
2026-10-16 12:07:08 +02:00
|
|
|
/** @var \Illuminate\Http\Request $this */
|
2026-07-08 14:55:18 +02:00
|
|
|
if ($this->has('offset') || $this->has('limit')) {
|
|
|
|
|
return Pagination::ofOffsetAndLimit(
|
|
|
|
|
$this->integer('offset', 0),
|
|
|
|
|
$this->integer('limit', $defaultPageSize)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Pagination::ofPage(
|
|
|
|
|
$this->integer('page', 1),
|
|
|
|
|
$this->integer(
|
|
|
|
|
'per_page',
|
|
|
|
|
// * Default laravel paginator name
|
|
|
|
|
$this->integer('pagination', $defaultPageSize)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-07-06 12:52:52 +02:00
|
|
|
}
|
|
|
|
|
}
|