chore: code refactor via rector
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Tests\Concerns;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use App\Models\Blog;
|
||||
use App\Models\Menu;
|
||||
use App\Models\Plan;
|
||||
@@ -60,18 +62,12 @@ trait LoadsApplicationData
|
||||
|
||||
// Try to load data from database, but fail gracefully if tables don't exist
|
||||
try {
|
||||
$menus = cache()->remember('app_menus', now()->addHours(6), function () {
|
||||
return Menu::all();
|
||||
});
|
||||
$menus = cache()->remember('app_menus', now()->addHours(6), Menu::all(...));
|
||||
|
||||
$blogs = cache()->remember('app_blogs', now()->addHours(6), function () {
|
||||
return Blog::where('is_published', 1)->get();
|
||||
});
|
||||
$blogs = cache()->remember('app_blogs', now()->addHours(6), fn() => Blog::query()->where('is_published', 1)->get());
|
||||
|
||||
$plans = cache()->remember('app_plans', now()->addHours(6), function () {
|
||||
return Plan::all();
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
$plans = cache()->remember('app_plans', now()->addHours(6), Plan::all(...));
|
||||
} catch (Exception) {
|
||||
// Set empty collections if database tables don't exist
|
||||
$menus = collect();
|
||||
$blogs = collect();
|
||||
@@ -79,13 +75,13 @@ trait LoadsApplicationData
|
||||
}
|
||||
|
||||
// Ensure we always have collections, even if cache is empty
|
||||
if (! ($menus instanceof \Illuminate\Support\Collection)) {
|
||||
if (! ($menus instanceof Collection)) {
|
||||
$menus = collect();
|
||||
}
|
||||
if (! ($blogs instanceof \Illuminate\Support\Collection)) {
|
||||
if (! ($blogs instanceof Collection)) {
|
||||
$blogs = collect();
|
||||
}
|
||||
if (! ($plans instanceof \Illuminate\Support\Collection)) {
|
||||
if (! ($plans instanceof Collection)) {
|
||||
$plans = collect();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user