edster - 3 months ago

My attachment

class AttachRealtorRelationToUser {

    public function handle()
    {
        $user = new UserModel();

        /* @var Hookable $user */
        if (!method_exists($user, 'bind')) {
            return;
        }

        /**
         * Get the user's buildings.
         *
         * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
         */
        $user->bind(
            'realtor',
            function () {
                /* @var UserModel $this */
                return $this->belongsTo(RealtorModel::class);
            }
        );
    }
}

I can query from realtor -> user via assigned field on the realtor stream, its getting $user->realtor that isn't working

If I dd $user->realtor I get the relation returned, but $user->realtor just always returns null. I tried forcing the column relations in the belongsTo but that isn't working eaither =/

Answer

edster - 3 months ago

Had it backwards, was supposed to be a hasOne and had to use ->first() when querying

edster - 3 months ago

Had it backwards, was supposed to be a hasOne and had to use ->first() when querying