I am new to laravel 8 and blade syntax.
I am working on a project where users (agents) can upload apartments.
i have agent table with corresponding model relationship
agent model
public function property()
{
return $this->hasMany(Property::class);
}
property model
public function agents()
{
return $this->belongsTo(Agent::class);
}
I used breeze to build up my registration and login
i want when an agent is logged in, i will display in his dash board list of his properties.
@foreach($properties as $property)
@if(($loop->count) > 0)
<td class="py-3 px-2">
<div class="inline-flex space-x-3 items-center">
<span>{{$property->propertyId}}</span>
</div>
</td>
<td class="py-3 px-2">{{$property->building}}</td>
<td class="py-3 px-2">{{$property->rent->name}}</td>
@else
You have not uploaded any apartment
@endif
@endforeach
but i get error “Undefined variable $properties”.
Meanwhile, {{ Auth::user()->othernames }} works fine.
AgentController
public function index()
{
return view ('dashboard', [
'agent' => Agent::all(),
'appointment'=>Appointment::all(),
'property'=>Property::all(),
'schedule'=>AgentSchedule::all()
]);
}
propertyController
public function create()
{
return view('pages.uploadapartment', [
'states'=> State::all(),
'areas'=>Area::all(),
'buildings'=>building::all(),
'buildingtypes'=>BuildingType::all(),
'rentpaymentmethods'=>rentpaymentmethod::all(),
'flattypes'=>flattype::all(),
]);
}