Skip to content

merging two relation BelongsToMany and hasMany and returning relation #17

@galexpert

Description

@galexpert

hi, it is possible to support merging two relation BelongsToMany and hasMany and returning relation laravel.
I need to merge two relationships (take and merge records from one table using different relationships...) and return the relationship in order to be able to perform actions with them... and then the method ->paginate($perPage, ['*'], 'page', $pageCurrent);

For example
There are item and seller models
seller.php

public function items()
   {
       return $this->belongsToMany(Item::class, 'item_seller', 'seller_id', 'item_id')->withPivot('id', 'enabled');
   }

public function myItems()
   {
       return $this->hasMany(Item::class, 'seller_id');
   }

I need to combine these two relations and return something similar

public function ALL_items_merged()
    {
        return $this->myItems() + $this-> items()
    }

$seller->ALL_items_merged()

for further work with this relationship
Thanks for any tips or solutions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions