Make Hidden child's relation /Laravel Eloquent

Model structure:

  • AccessoryGroup (hasMany: accessories)
  • Accessory (belongsTo: accessory_group)

Get all accessory groups with accessories (with accesory_group)

In accessories I needed accessory_group relation, to create some custom attribute (appends)

But after usage I don't won't my Api to return relation from accessories->accessory_group

AccessoryGroup
            ::with([
                'accessories' => function ($query) {
                    $accessory = $query->getRelated();
                    // Can I somehow use this $accessory relation for my problem
                    // something like $accessory->makeHidden('accessory_group'); - not working
                },
                'accessories.accessory_group',
            ])
            ->get();

when i add public $hidden = ['accesory_group']; in Accessory model I get what i want, but then it's always hidden (always need to use makeVisible)



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Network Error and Timeout on Authorize.net JS