mercredi 25 décembre 2019

Trying to get property 'RmFName' of non-object

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.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZnJHBg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire