Files
nuhodds_fi4/app/Livewire/Mapper/LoadProvider.php
T

40 lines
1.2 KiB
PHP

<?php
namespace App\Livewire\Mapper;
use App\Models\Event;
use App\Models\Mapper;
use Illuminate\Support\Carbon;
class LoadProvider
{
public static function load($search_values, $user)
{
$res = Event::query()->where('betradar_id', '>', 0)->pluck('betradar_id');
foreach ($res as $betradar_id) {
Mapper::where('betradar_id', $betradar_id)->delete();
}
if (is_array($search_values) and \count($search_values)) {
return Mapper::query()
->whereDate('starttime', '>', Carbon::now())
->where('sport_id', $user->sport_id)
->where('provider_id', $user->provider_id)
->where(function ($query) use ($search_values) {
foreach ($search_values as $value) {
$query->orWhere('home', 'LIKE', '%'.$value.'%')
->orWhere('away', 'LIKE', '%'.$value.'%');
}
});
} else {
return Mapper::query()
->whereDate('starttime', '>', Carbon::now())
->where('sport_id', $user->sport_id)
->where('provider_id', $user->provider_id);
}
}
}