belongsTo('App\User','user_id','id'); } public function getUserNameAttribute() { return $this['user']?$this['user']['name']:null; } }