File: /home/imensosw/www/mpl.imenso.co/app/Typeahead/PromoterTypeahead.php
<?php
namespace App\Typeahead;
use App\Models\User;
use Auth;
use DB;
class PromoterTypeahead extends TypeaheadBuilder
{
public function get($total = 10)
{
$query = User::where('type_id', 4)
->where('promoter_name', 'LIKE', '%'.$this->search_string.'%');
if ($this->exclude) {
$query = $query->whereNotIn('id', $this->exclude);
}
$user = Auth::user();
if ($this->connected_only == true) {
if ($user->isVenue()) {
$user_promoter_connections = DB::table('promoter_venue_connections')->where('venue_id', $user->id)->pluck('promoter_id');
} elseif ($user->isBand()) {
$user_promoter_connections = DB::table('artist_promoter_connections')->where('artist_id', $user->id)->pluck('promoter_id');
} elseif ($user->isFan()) {
$user_promoter_connections = DB::table('fan_promoter_connections')->where('fan_id', $user->id)->pluck('promoter_id');
} else {
$user_promoter_connections = [];
}
$query = $query->whereIn('id', $user_promoter_connections);
}
$this->data = $query->take($total)
->pluck('promoter_name', 'id');
return $this->output();
}
}