Why won't this work? [code] That function doesn't work. Here's the model: [code]
- User
Why won't this work?
public function getThreeTickets() { $tickets = Ticket::limit(3)->with(['ticketable, category'])->get(); return response()->json($tickets); }That function doesn't work. Here's the model:
<?php declare(strict_types=1); namespace Src\Spedgrow\Ticket\Domain\Model; use Illuminate\Database\Eloquent\Model; use Src\Spedgrow\Organization\Domain\Model\Organization; use Src\Spedgrow\Vendor\Domain\Model\Category; class Ticket extends Model { protected $fillable = [ 'organization_id', 'ticketable_id', 'ticketable_type', 'category_id', 'title', 'description', 'remark', 'priority', 'due_date', 'handle_by', 'status', ]; public function scopeFilter($query, $filters) { $query->when($filters['search'] ?? false, function ($query, $search) { $query->where('title', 'like', '%' . $search . '%'); }); $query->when($filters['category'] ?? false, function ($query, $category) { $query->whereHas('category', function ($query) use ($category) { $query->where('name', $category); }); }); $query->when($filters['organization'] ?? false, function ($query, $org_id) { if ($org_id != 'null') { $query->where('organization_id', $org_id); } }); } public function category() { return $this->belongsTo(Category::class); } public function ticketable() { return $this->morphTo(); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } } - Assistant