|
|
@@ -4,10 +4,12 @@ namespace App\Services;
|
|
|
|
|
|
use App\Models\Address;
|
|
|
use App\Models\Client;
|
|
|
+use App\Models\Media;
|
|
|
use App\Models\Provider;
|
|
|
use App\Rules\ScheduleBusinessRules;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
class SearchService
|
|
|
{
|
|
|
@@ -54,6 +56,7 @@ class SearchService
|
|
|
->when($name, fn ($q) => $q->where('provider_user.name', 'ILIKE', "%{$name}%"))
|
|
|
->select(
|
|
|
'providers.id as provider_id',
|
|
|
+ 'providers.profile_media_id',
|
|
|
'provider_user.name as provider_name',
|
|
|
'provider_address.district',
|
|
|
'provider_address.latitude as provider_latitude',
|
|
|
@@ -87,18 +90,33 @@ class SearchService
|
|
|
$providers = $baseQuery->get();
|
|
|
}
|
|
|
|
|
|
- return $providers
|
|
|
- ->when(
|
|
|
- $date,
|
|
|
- fn ($collection) => $collection->whereIn(
|
|
|
- 'provider_id',
|
|
|
- ScheduleBusinessRules::getAvailableProviderIdsForDate(
|
|
|
- $date,
|
|
|
- $collection->pluck('provider_id')
|
|
|
- )->toArray()
|
|
|
- )->values()
|
|
|
- )
|
|
|
- ->toArray();
|
|
|
+ $filtered = $providers->when(
|
|
|
+ $date,
|
|
|
+ fn ($collection) => $collection->whereIn(
|
|
|
+ 'provider_id',
|
|
|
+ ScheduleBusinessRules::getAvailableProviderIdsForDate(
|
|
|
+ $date,
|
|
|
+ $collection->pluck('provider_id')
|
|
|
+ )->toArray()
|
|
|
+ )->values()
|
|
|
+ );
|
|
|
+
|
|
|
+ $mediaIds = $filtered->pluck('profile_media_id')->filter()->unique()->values();
|
|
|
+ $mediaUrls = [];
|
|
|
+ if ($mediaIds->isNotEmpty()) {
|
|
|
+ Media::whereIn('id', $mediaIds)->get()->each(function ($media) use (&$mediaUrls) {
|
|
|
+ $mediaUrls[$media->id] = $media->path
|
|
|
+ ? Storage::temporaryUrl($media->path, now()->addMinutes(60))
|
|
|
+ : null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return $filtered->map(function ($item) use ($mediaUrls) {
|
|
|
+ $arr = is_array($item) ? $item : $item->toArray();
|
|
|
+ $arr['profile_media_url'] = $mediaUrls[$arr['profile_media_id'] ?? null] ?? null;
|
|
|
+ unset($arr['profile_media_id']);
|
|
|
+ return $arr;
|
|
|
+ })->values()->toArray();
|
|
|
}
|
|
|
|
|
|
private function distanceSelect(?float $clientLatitude, ?float $clientLongitude): \Illuminate\Contracts\Database\Query\Expression
|