Cannot get its own value in the laravel database association?

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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea9461-1f47.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea9461-1f47.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?