I'm getting "Trying to get property of non-object" while trying to this code
Database
roomfloor
-RmFID (PK)
-RmFName (FK)
roomtype
-RmTypeID (PK)
-RmTypeBed
-RmTypeRent
-RmFName (FK)
class RoomType extends Model
{
protected $primaryKey = 'RmTypeID';
protected $table = 'roomtype';
protected $fillable = ['RmTypeID','RmTypeBed','RmTypeRent','RmFName'];
public function roomfloors(){
return $this->belongsTo(RoomFloor::class,'RmFName','RmFName');
}
}
class RoomFloor extends Model
{
protected $primaryKey = 'RmFID';
public $timestamps = false;
protected $table = 'roomfloor';
protected $fillable =['RmFID','RmFName'];
public function roomtypes(){
return $this->hasOne(RoomType::class,'foreign_key', 'RmFName');
}
}
public function index()
{
$roomtype = RoomType::with('roomfloors')->get();
return view('roomtype.index',[
'roomtypes'=>$roomtype
]);
}
Show Value :
@foreach ($roomtypes as $roomtype)
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
@endforeach
Thank you.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire