ldc-cocotte/app/Providers/AppServiceProvider.php

94 lines
3.2 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Range;
use App\Models\Tag;
use App\Models\Setting;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\URL;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
URL::forceScheme('https');
if (config('app.env') !== 'local') {
setlocale(LC_TIME, config('app.locale') . "_" . strtoupper(config('app.locale')) . '.utf8');
}
if (config('app.env') === 'local') {
setlocale(LC_TIME, strtoupper(config('app.locale')) . "_" . config('app.locale') . '.utf8');
}
if (Schema::hasTable('settings')) {
// The "settings" table exists...
config([
'bosettings' => Setting::all()
->keyBy('key')
// Key every setting by its name.
->transform(function ($setting) {
return $setting->value;
// Return only the value.
})
->toArray()
// Make it an array.
]);
$front_settings = Setting::where('key', 'LIKE', 'theme_%')->get();
// Front theme settings.
View::share('front_settings', $front_settings);
}
if (Schema::hasTable('ranges')) {
// On partage les ranges (gammes produit).
$ranges = Range::where('status', '1')->get();
View::share('published_ranges', $ranges);
}
if (Schema::hasTable('tags')) {
// On partage les tags.
$tags = Tag::where('status', '1')->orderBy('order', 'ASC')->get();
View::share('published_tags', $tags);
}
// Use blade directives helper to prevent blade files from being cached.
Blade::directive('fmt_currency_without_auth', function ($expression) {
return "<?php echo \App\Helpers\BladeDirectivesHelper::formatPriceValue($expression); ?>";
});
Blade::directive('fmt_currency', function ($expression) {
return "<?php echo \App\Helpers\BladeDirectivesHelper::formatCurrency($expression); ?>";
});
Blade::directive('fmt_currency_without_ttc', function ($expression) {
return "<?php echo \App\Helpers\BladeDirectivesHelper::formatCurrency($expression); ?>";
});
Blade::directive('fmt_sellunit', function ($expression) {
return "<?php echo \App\Helpers\BladeDirectivesHelper::formatSellUnit($expression); ?>";
});
Blade::directive('excerpt_product_title', function ($expression) {
return "<?php echo \App\Helpers\BladeDirectivesHelper::excerptTitle($expression); ?>";
});
// Default paginator template for back Office.
Paginator::useBootstrap();
}
}