38 lines
1 KiB
PHP
38 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Articles;
|
|
use App\Models\Moments;
|
|
use App\Models\Products;
|
|
use App\Models\Recipes;
|
|
|
|
class MomentsController extends Controller
|
|
{
|
|
public function index(Moments $moment)
|
|
{
|
|
if (!$moment->status) {
|
|
abort(404);
|
|
}
|
|
$otherMoments = Moments::where([
|
|
['slug', '<>', $moment->slug], ['status', 1]
|
|
])->inRandomOrder()->limit(2)->get();
|
|
|
|
$featuredIds = array_unique(explode(';', $moment->featured_ids));
|
|
$featuredObjects = [];
|
|
|
|
switch ($moment->featured_type) {
|
|
case "recettes":
|
|
$featuredObjects = Recipes::find($featuredIds);
|
|
break;
|
|
case "produits":
|
|
$featuredObjects = Products::find($featuredIds);
|
|
break;
|
|
case "articles":
|
|
$featuredObjects = Articles::find($featuredIds);
|
|
break;
|
|
}
|
|
|
|
return view('front.moment', compact('moment', 'otherMoments', 'featuredObjects'));
|
|
}
|
|
}
|