Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

LaravelDaily/Laravel-Support-Ticketing

294 stars
2 code files
View LaravelDaily/Laravel-Support-Ticketing on GitHub

app/Ticket.php

Open in GitHub
use 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 GitHub
use 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));
//
}
//
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.