I have this problem when I want to open specific page by id.
now I am trying to shown title on my page with specific id, which have post in db, but that error stopped me.
there are my code.
route
Route::get('/tickets/{id}', [TicketsController::class, 'show'])->name('tickets.show');
controller
public function show($id) {
$tickets = Tickets::with('companies')->get();
$ticketscomp = Companies::with('tickets')->get();
$severities = Severities::with('tickets')->get();
$ticketspage = Tickets::findOrFail($id);
return view('tickets.chat', compact('ticketspage'))->with(['tickets'=> $tickets])->with(['ticketscomp'=>$ticketscomp])->with(['severities'=>$severities])->with(['ticketspage'=>$ticketspage]);
//dd($ticketspage->toArray());
blade.php
@foreach ($ticketspage as $item)
<h6 class="mb-1; ticket-list-title;">{{ $item->ticket_title }}</h6>
@endforeach
When I dd post. post is opening by id with included information.
2
Answers
::findOrFail()
returns a single model instance. You do not need a@foreach()
loop.I fix this now but if someone have problem like me just read my comment.
Just remove foreach and type like this