Search code examples
phplaravellaravel-artisan

Attempt to read property "ticket_title" on bool


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


Solution

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

    <h6 class="mb-1; ticket-list-title;">{{ $ticketspage->ticket_title }}</h6>