dealhub/app/Queries/ExplorePageDealsQuery.php
kusowl 985dd967e4 feature(search deals)
- make deals reachable
- add recent search feature
- add animation in profile menu
- refactor blade markup of explore page
2026-01-20 18:43:13 +05:30

36 lines
1.1 KiB
PHP

<?php
namespace App\Queries;
use App\Models\Deal;
use Illuminate\Database\Eloquent\Builder;
final readonly class ExplorePageDealsQuery
{
/**
* @return Builder<Deal>
*/
public function builder(): Builder
{
return Deal::query()
->select([
'id', 'title', 'description', 'image', 'active', 'slug', 'link',
'deal_category_id', 'user_id',
])
// Select additional details
->with([
'category:id,name',
'broker' => function ($query) {
$query->select('id', 'name', 'email', 'role_type', 'role_id')
->with('type');
},
])
// Select only admin-approved deals
->tap(fn ($q) => (new Deal)->withActiveDeals($q))
// Check if the current user interacted with the deal
->tap(fn ($q) => (new Deal)->withCurrentUserInteractions($q))
->tap(fn ($q) => (new Deal)->withLikePerDeal($q))
->tap(fn ($q) => (new Deal)->withRedirectionPerDeal($q));
}
}