Files
ntspi-app/app/Containers/Widget/Tasks/FindPostByIdTask.php
T
2026-03-20 21:47:02 +05:00

22 lines
539 B
PHP
Executable File

<?php
namespace App\Containers\Widget\Tasks;
use App\Containers\Article\Models\Post;
use App\Containers\Widget\UI\API\Transformers\PostThumbnailResource;
use Illuminate\Support\Facades\Cache;
class FindPostByIdTask
{
public function run(int $id)
{
$cacheKey = 'post_' . $id;
return Cache::remember($cacheKey, now()->addMinutes(10), function () use ($id) {
return new PostThumbnailResource(
Post::query()->with('category')->find($id)->firstOrFail()
);
});
}
}