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 user()
{
return $this->hasOne('App\User', 'id', 'user_id')->select(array('id', 'username'));
}
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'));
current view:
<div class="container">
ID: {{$ticket->id}}
title: {{ $ticket->title}}<br>
status: {{ returnStatus($ticket->status) }}<br>
Ticket created: {{ $ticket->created_at }}<br>
@if (!$ticket->supporter)
supporter:-<br></br></br>
@else
supporter {{ $ticket->supporter->username }}<br></br>
@endif
@foreach($ticket->ticket_replie as $reply)
@if ($reply->file == null)
reply text: {{ $reply->text }}</br>
written by: {{ $reply->user->username }}
reply created at: {{$reply->created_at}}</br></br>
@else
reply text: {{ $reply->text }}</br>
file: <a href="/path/to/file/{!! $reply->file->name !!}">Download file</a><br>
written by: {{ $reply->user->username }}
reply created at: {{$reply->created_at}}</br></br>
@endif
@endforeach
</div>
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 "detect" the role of the user who answered? If this statement will be true, the reply was created by user(if Auth::user()->id == $reply->user->id). But I would like to do this check into my controller and pass it to the view. What's the best way to solve this tricky task?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire