skip to Main Content

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.

This is dd

2

Answers


  1. ::findOrFail() returns a single model instance. You do not need a @foreach() loop.

    <h6 class="mb-1; ticket-list-title;">{{ $ticketspage->ticket_title }}</h6>
    
    Login or Signup to reply.
  2. I fix this now but if someone have problem like me just read my comment.

    Just remove foreach and type like this

    <h6 class="mb-1; ticket-list-title;">{{ $ticketspage->ticket_title }}</h6>
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search