-1
The variable $imoveis in Blade is undefined, for me it is correct in the code.
@extends('layouts.main')
@section('title', 'Web Room')
@section('content')
<h1>Imoveis web</h1>
<div id="search-container" class="col-md-12">
<h1>Busque um imóvel</h1>
<form action="">
<input type="text" id="search" name="search" class="form-control" placeholder="Procure um imóvel..">
</form>
</div>
<div id="imoveis-container" class="col-md-12">
<h2>Próximos Imoveis</h2>
<p>Veja os eventos dos proximos dias</p>
<div id="cards-container" class="row">
@foreach($imoveis as $imovel)
<div class="card-col-md-3">
<img src="/img/banner.jpg" alt="{{$imovel->titulo}}">
<div class="card-body">
<p class="card-date">10/09/2021</p>
<h5 class="card-title">{{$imovel->titulo}}</h5>
<p class="card-participantes">x participantes</p>
<a href="#" class="btn btn-primary">Saber mais</a>
</div>
</div>
@endforeach
</div>
@endsection
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Imovel;
class ImoveisController extends Controller
{
public function index(){
$imoveis = Imovel::all();
dd($imoveis);
return view('welcome', ['imoveis' => $imoveis]);
}
public function create(){
return view('imoveis.create');
}
}
Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Imovel extends Model
{
use HasFactory;
protected $table = "imoveis";
protected $fillable = ['titulo','descricao','valor_aluguel','endereco'];
}
You made a
dd($imoveis)in your Controller, then Blade will not run. If it is running yet, it is not from the methodindex. If it is from it, would be displayed the result ofdd. Which of the two is?– Woss
Can you post the full error text? It may be that q is undefined one of the immovable->title fields for example
– Ademir Mazer Jr - Nuno