lundi 15 juillet 2019

Eloquent relations - empty collections

I have two tables tblFormStatus and tblForms which have following structures

table tblFormStatus

Id        Description
-----------------------
1         Pending
2         Aprroved
3         Rejected

table tblForms

Id        StatusId        DateCreated
--------------------------------------
1          1              2018-6-15
2          2              2019-6-15

and i have the following model relations in laravel

Forms.php

public function formstatus()
{
     return $this->belongsTo(FormStatus::class, 'Statusid');
}

and FormStatus.php

public function forms()
{
     return $this->hasMany(Forms::class,'StatusId');
}

so in formcontroller.php i have the code to pull all data from tblforms with a dump

$forms = Forms::with('formstatus')->get();
dd($forms);

and i get an null collections

#relations: array:1 [▼
        "formstatus" => null
      ]

i am very new to laravel and i tried different things but none worked. Can anyone please suggest me where i am doing wrong and how to fix.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire