Laravel - how to makeVisible an attribute in a Laravel relation?

后端 未结 3 1592
时光说笑
时光说笑 2020-12-18 05:04

I use in my model code to get a relation

class User extends Authenticatable
{
    // ...
    public function extensions()
    {
        return $this->belo         


        
3条回答
  •  伪装坚强ぢ
    2020-12-18 05:15

    The highest voted answer didn't seem to work for me (the relations attribute seems to be a protected array now so can't be used as a collection in @DevK's answer), I instead used:

    $parent->setRelation('child', $parent->child->first()->setVisible(['id']));
    

提交回复
热议问题