70 lines
2.2 KiB
PHP
70 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\GeneralConfigType;
|
|
use App\Models\Actu;
|
|
use App\Models\Tag;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class ActuController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$tags = Tag::has('actus')->get();
|
|
$actus = Actu::where('status', true)
|
|
->with('tags:id')
|
|
->get(['id'])
|
|
->mapWithKeys(function ($actu) {
|
|
return [
|
|
$actu->id => [
|
|
'id' => $actu->id,
|
|
'tags' => $actu->tags->mapWithKeys(function ($tag) {
|
|
return [$tag->id => $tag->id];
|
|
})->all()
|
|
]
|
|
];
|
|
})->all();
|
|
$generalConfig = app()->view->getShared()['GeneralConfigGlobal'] ?? null;
|
|
$generalConfig = $generalConfig ? $generalConfig->where('type', GeneralConfigType::actu())->first() : null;
|
|
return view('front.actu.index', [
|
|
'generalConfig' => $generalConfig,
|
|
'paginate' => 9,
|
|
'actus' => $actus,
|
|
'tags' => $tags
|
|
]);
|
|
}
|
|
|
|
public function view(Actu $actu)
|
|
{
|
|
$relatedActus = Actu::whereHas('tags', function ($q) use ($actu) {
|
|
$q->whereIn('id', $actu->tags->pluck('id'));
|
|
})->where('id', '!=', $actu->id)->whereStatus(true)
|
|
->inRandomOrder()->limit(3)->get();
|
|
$generalConfig = app()->view->getShared()['GeneralConfigGlobal'] ?? null;
|
|
$generalConfig = $generalConfig ? $generalConfig->where('type', GeneralConfigType::actu())->first() : null;
|
|
return \view('front.actu.show', [
|
|
'generalConfig' => $generalConfig,
|
|
'actu' => $actu,
|
|
'relatedActus' => $relatedActus
|
|
]);
|
|
}
|
|
|
|
public function renderActu(Actu $actu)
|
|
{
|
|
if (!request()->wantsJson()) {
|
|
abort(404);
|
|
}
|
|
return response()->json(
|
|
Cache::rememberForever(
|
|
"ActuRendered_$actu->id",
|
|
function () use ($actu) {
|
|
return \base64_encode(\view(
|
|
'front.actu.card',
|
|
['actu' => $actu]
|
|
)->render());
|
|
}
|
|
)
|
|
);
|
|
}
|
|
}
|