I would like to order my ticket_replies by date (created_at). Any tipp on how to get the ticket_replies ordered by date (oldest one to the top, newest at least). Did I need to use sortByDesc() or the orderBy() statement? Tabe design:
tickets: |id|supp_id|title|user_id|...
ticket_replies: |id|ticket_id|user_id|text|created_at
files: |id|ticket_replie_id|name
controller:
$ticket = Auth::user()->tickets()->where('id', $id)->with(['ticket_replie.file'])->orderBy('ticket_replie.created_at')->firstOrFail();
return view('protected.ticketDetail', compact('ticket'));
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>
@else
reply text: {{ $reply->text }}</br>
file: <a href="/path/to/file/{!! $reply->file->name !!}">Download file</a><br>
@endif
reply created at: {{$reply->created_at}}</br></br>
@endforeach
</div>
When I run this code it fails saying:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ticket_replies.created_at' in 'order clause' (SQL: select * from `tickets` where `tickets`.`user_id` = 1 and `tickets`.`user_id` is not null and `id` = 43 order by `ticket_replies`.`created_at` asc limit 1)
Did I need to modify my model of ticket_replies for this or did I need to take an other way to get this solved?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire