Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merging two relation BelongsToMany and hasMany and returning relation #17

Open
galexpert opened this issue Sep 25, 2023 · 0 comments
Open

Comments

@galexpert
Copy link

galexpert commented Sep 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant