Home > Enterprise >  Attempt to read property "ticket_title" on bool
Attempt to read property "ticket_title" on bool

Time:12-12

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 >{{ $item->ticket_title }}</h6>
     @endforeach

When I dd post. post is opening by id with included information.

This is dd

CodePudding user response:

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

<h6 >{{ $ticketspage->ticket_title }}</h6>

CodePudding user response:

I fix this now but if someone have problem like me just read my comment.

Just remove foreach and type like this

<h6 >{{ $ticketspage->ticket_title }}</h6>

  • Related