ldc-legaulois/app/Providers/AppServiceProvider.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Providers;
use App\Models\Articles;
2020-11-04 15:07:21 +01:00
use App\Models\Moments;
use Illuminate\Support\Facades\Cache;
2021-03-21 22:51:19 +01:00
use Illuminate\Support\Facades\URL;
2020-11-04 15:07:21 +01:00
use Illuminate\Support\Facades\View;
2020-07-23 10:29:36 +02:00
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
if (config('app.env') !== 'local') {
2021-03-21 22:51:19 +01:00
URL::forceScheme('https');
}
if (!app()->runningInConsole()) {
2021-03-26 12:41:11 +01:00
if (!Cache::has('momentFiche')) {
$momentFiche = Moments::where([['star_moment', 1], ['status', 1]])->first();
Cache::put('momentFiche', $momentFiche);
}
2021-03-26 12:41:11 +01:00
View::share('momentFiche', Cache::get('momentFiche') ?? false);
// Liste des actus pour le footer
$actus = Cache::get('actusGlobal');
2021-03-26 12:41:11 +01:00
if (!Cache::has('actusGlobal')) {
2021-03-21 22:51:19 +01:00
$actus = Articles::where([['status', 1], ['category_id', 1]])
->orderBy('updated_at', 'DESC')->limit(3)->get();
Cache::put('actusGlobal', $actus);
}
2021-03-26 12:41:11 +01:00
View::share('actusGlobal', Cache::get('actusGlobal') ?? false);
}
2020-07-23 10:29:36 +02:00
}
}