public function roles()
{
return $this->hasOne("App\Models\Role")->where("type",$this->type);
}
$this- > type
can"t get any value? Why is that? The value of
$this- > attributes
is also an empty array. Why?
public function roles()
{
return $this->hasOne("App\Models\Role")->where("type",$this->type);
}
$this- > type
can"t get any value? Why is that? The value of
$this- > attributes
is also an empty array. Why?
this depends on how you use it, if you use:
$Obj- > with (['roles'])-> get ();
this usage should not get a value.
if it is:
$model = $Obj- > find ('1');
$result = $model- > roles ()-> get ();
should have a result.
is your model itself empty? You can print out $this directly to see if it is a recorded model.
just now I specifically tested that your above statement can be executed successfully, and you can get the properties under this.