This will take a moment, but it will help you to understand my problem. I'm working hard on a support ticket system. This is my current table design:
tickets: |id|supp_id|title|user_id|...
ticket_replies: |id|ticket_id|user_id|text|created_at
files: |id|ticket_replie_id|name
ticket model:
public function ticket_replie()
{
return $this->hasMany('App\ticket_replie', 'ticket_id', 'id');
}
public function supporter()
{
return $this->hasOne('App\User', 'id', 'supp_id');
}
ticket_replies model:
public function file()
{
return $this->hasOne('App\File', 'ticket_replie_id', 'id')->select(array('name'));
}
my controller
$ticket = Auth::user()->tickets()->where('tickets.id', $id)->with(['ticket_replie.file'])->orderBy('created_at', 'desc')->firstOrFail();
return view('protected.ticketDetail', compact('ticket'));
At the moment I'm at the ticket details page (this page shows all replies for a specified ticket). Each ticket replie can contain exactly one attachment (this is optional). I would like to show now each answer to the ticket and who made this answer (user OR supporter). What's the best way to retrieve if the replie was made by the user or by the supporter? It would be the best to do this check not in the view I think (just pass an item in the collection to the view and check in the view if item isset?!). Any suggestions how to do so? My main goal is to archieve low SQL load, by using a low amount of querys.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire