Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

543
Visualizações
Attempt to read property "title" on bool when trying to load a single post

I'm trying to load a single blog post in laravel, but every time I click on a single post, I get the error 'Attempt to read property "title" on bool.' I've tried looking up the error but I haven't found a solution and don't know what causes the error. Here's my code

Blade file:

@foreach($AboutUs as $about_us)
    <div class="col-lg">
        <img src="images/agenda.png" class="img-fluid shadow-lg" style="">
        <p class="mt-3 text-success fw-bold fs-5 text-lg-start">{{$about_us->title}}</p>
        <p class="fs-6 text-lg-start"> {{$about_us->description}}</p>
        <p class="text-success fw-bold text-lg-start"><a href="/about.show/{{$about_us->id}}" class="text-success text-decoration-none">{{$about_us->button}}</a></p>
        <!--<img src="images/hr-2.png" class="img-fluid float-start my-2">-->
    </div>
@endforeach

Controller:

public function show($id)
{
    $data = AboutUs::find($id);
    return view('about.show', ['AboutUs' => $data])
        ->with(['AboutUs' => AboutUs::find($id)]);
}

Routes:

Route::get('/about.show/{id}', 'App\Http\Controllers\WelcomeController@show')->name('about.show');

Can anyone offer any assistance?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

OK, it's a bit of a mess, to be honest.

The short answer is that :

$data = AboutUs::find($id);

is returning one item, not a collection of items. You can't loop through that like you're trying to do, hence the error.

For some reason, though, you're then loading that again with when you're returning your view?

return view('about.show',['AboutUs'=>$data])->with(['AboutUs' => AboutUs::find($id),]);

So, for starters, you can probably simplify that - assuming you're wanting to load a post, in your controller you can then instead :

public function show($id) {
   $post = AboutUs::find($id);
   return view('about.show')->with(compact('post');
}

But then in your blade file you're trying to loop through your $AboutUs variable as though it's a collection, but it's not - find($id) returns a single model instance.

So naturally Blade is getting a bit confused.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda