ldc-boutique-cnc/app/Providers/AppServiceProvider.php

99 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2020-10-30 17:26:00 +01:00
<?php
namespace App\Providers;
use App\Models\Range;
use App\Models\Tag;
2021-05-06 17:18:25 +02:00
use App\Models\Setting;
use Illuminate\Support\Facades\View;
2020-10-30 17:26:00 +01:00
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Schema;
2022-09-03 16:56:16 +02:00
use Illuminate\Support\Facades\URL;
2020-10-30 17:26:00 +01:00
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
2022-09-03 16:56:16 +02:00
URL::forceScheme('https');
2021-03-23 10:23:05 +01:00
if (config('app.env') !== 'local') {
2021-06-07 16:12:13 +02:00
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');
2021-03-23 10:23:05 +01:00
}
2021-03-18 08:40:20 +01:00
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.
]);
2022-09-03 16:56:16 +02:00
$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);
}
2021-05-06 17:18:25 +02:00
Blade::directive('fmt_currency', function ($expression) {
2021-11-03 17:23:25 +01:00
return "<?php
if(is_float($expression)) {
echo sprintf('%s € TTC', number_format($expression, 2, ',', ' '));
} else {
echo $expression;
} ?>";
2021-04-08 18:05:17 +02:00
});
Blade::directive('fmt_sellunit', function ($expression) {
2022-08-25 12:26:43 +02:00
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); } ?>";
}
});
2022-08-25 12:26:43 +02:00
Blade::directive('excerpt_product_title', function ($expression) {
$limit = config('theme.max_product_title_length');
return "<?php echo Illuminate\Support\Str::limit($expression,$limit) ?>";
});
2022-09-03 16:56:16 +02:00
// Default paginator template for back Office.
Paginator::useBootstrap();
2020-10-30 17:26:00 +01:00
}
}