ldc-legaulois/app/Providers/AppServiceProvider.php

55 lines
1.4 KiB
PHP

<?php
namespace App\Providers;
use App\Models\Articles;
use App\Models\Moments;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\View;
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 (!app()->runningInConsole()) {
$momentFiche = Cache::get('momentFiche');
if (!$momentFiche) {
$momentFiche = Moments::where([['star_moment', 1], ['status', 1]])->first();
Cache::put('momentFiche', $momentFiche);
}
if ($momentFiche) {
View::share('momentFiche', $momentFiche);
}else{
View::share('momentFiche', false);
}
// Liste des actus pour le footer
$actus = Cache::get('actusGlobal');
if (!$actus) {
$actus = Articles::where([['status', 1], ['category_id', 1]])->orderBy('updated_at', 'DESC')->limit(3)->get();
Cache::put('actusGlobal', $actus);
}
if ($actus) {
View::share('actusGlobal', $actus);
} else {
View::share('actusGlobal', false);
}
}
}
}