refactor multiple widget controllers; replace caching logic with action classes for data retrieval, enhancing code clarity and maintainability
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?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()
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user