ldc-boutique-cnc/app/Providers/AppServiceProvider.php
2022-09-03 16:56:16 +02:00

90 lines
2.8 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\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');
}
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.
]);
// On partage les ranges (gammes produit).
$ranges = Range::where('status', '1')->get();
View::share('published_ranges', $ranges);
// On partage les tags.
$tags = Tag::where('status', '1')->orderBy('order', 'ASC')->get();
View::share('published_tags', $tags);
$front_settings = Setting::where('key', 'LIKE', 'theme_%')->get();
// Front theme settings.
View::share('front_settings', $front_settings);
Blade::directive('fmt_currency', function ($expression) {
return "<?php
if(is_float($expression)) {
echo sprintf('%s € TTC', number_format($expression, 2, ',', ' '));
} else {
echo $expression;
} ?>";
});
Blade::directive('fmt_sellunit', function ($expression) {
if (config('bosettings.sell_unit_management') == "strict") {
return "<?php if(!empty($expression)) { echo sprintf('/ %s', SellUnit::make($expression)->label); } ?>";
} else {
return "<?php if(!empty($expression)) { echo sprintf('/ %s', $expression); } ?>";
}
});
Blade::directive('excerpt_product_title', function ($expression) {
$limit = config('theme.max_product_title_length');
return "<?php echo Illuminate\Support\Str::limit($expression,$limit) ?>";
});
// Default paginator template for back Office.
Paginator::useBootstrap();
}
}