-
app/Ticket.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; class Ticket extends Model implements HasMedia { // public function scopeFilterTickets($query) { $query->when(request()->input('priority'), function($query) { $query->whereHas('priority', function($query) { $query->whereId(request()->input('priority')); }); }) ->when(request()->input('category'), function($query) { $query->whereHas('category', function($query) { $query->whereId(request()->input('category')); }); }) ->when(request()->input('status'), function($query) { $query->whereHas('status', function($query) { $query->whereId(request()->input('status')); }); }); } // }
-
app/Http/Controllers/Admin/TicketsController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Ticket; use Illuminate\Http\Request; class TicketsController extends Controller { public function index(Request $request) { if ($request->ajax()) { $query = Ticket::with(['status', 'priority', 'category', 'assigned_to_user', 'comments']) ->filterTickets($request) ->select(sprintf('%s.*', (new Ticket)->table)); // } // } // }