48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Mapper;
|
|
|
|
use App\Models\Element;
|
|
use App\Models\Event;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class LoadEvents
|
|
{
|
|
public static function load($search_values)
|
|
{
|
|
if ($search_values) {
|
|
$element_ids = Element::where(function ($query) use ($search_values) {
|
|
foreach ($search_values as $value) {
|
|
$query->orWhere('name', 'LIKE', '%'.$value.'%');
|
|
}
|
|
})->pluck('id')->toArray();
|
|
|
|
$query = Event::query()
|
|
->with('home')
|
|
->with('away')
|
|
->where('sport_id', auth()->user()->sport_id)
|
|
->whereDate('starttime', '>', Carbon::now())
|
|
->where(function ($query) use ($element_ids) {
|
|
$query->orWhereIn('home_id', $element_ids)->orWhereIn('away_id', $element_ids);
|
|
});
|
|
} else {
|
|
$query = Event::query()
|
|
->with('home')
|
|
->with('away')
|
|
->where('sport_id', auth()->user()->sport_id)
|
|
->whereDate('starttime', '>', Carbon::now());
|
|
}
|
|
|
|
switch (Auth::user()->provider_id) {
|
|
case 2:
|
|
// BETSAPI
|
|
return $query->where('betsapi_id', 0);
|
|
|
|
default:
|
|
return $query->with('event_bookmaker')->doesntHave('event_bookmaker');
|
|
break;
|
|
}
|
|
}
|
|
}
|