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,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Tasks;
|
||||
|
||||
use App\Containers\AppStructure\Models\Page;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class FindPageByIdTask
|
||||
{
|
||||
public function run(int $id)
|
||||
{
|
||||
$cacheKey = 'page_' . md5($id);
|
||||
|
||||
return Cache::remember($cacheKey, now()->addHours(1), function () use ($id) {
|
||||
return Page::where('id', '=', $id)
|
||||
->with('section.pages.section', 'section.mainSection')
|
||||
->firstOrFail();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user