Giter Club home page Giter Club logo

laravel-has-many-merged's Introduction

Hi there ๐Ÿ‘‹

laravel-has-many-merged's People

Contributors

dependabot[bot] avatar korridor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-has-many-merged's Issues

Inverse relationship

Hi, I was wondering if by any change you could add support for inverse relationships. Same functionality but from the other side of the relartion. Thanks!

Order/Sort parent based on Childrens

In my application,
I have MessageThread and Message model.

This is the migration for message_threads table:

            $table->string('sender_number', 15);
            $table->string('receiver_number', 15);

            $table->string('sender_number_receiver_number', 30)->virtualAs('CONCAT(`sender_number`, "-", `receiver_number`)');
            $table->string('receiver_number', 30)->virtualAs('CONCAT(`receiver_number`, "-", `sender_number`)');

            $table->string('contact_name', 75)->nullable();
            $table->unique(['sender_number', 'receiver_number']);

And messages

            $table->string('from', 15);
            $table->string('to', 15);

            $table->string('from_to', 30)->virtualAs('CONCAT(`from`, "-", `to`)');
            $table->string('to_from', 30)->virtualAs('CONCAT(`to`, "-", `from`)');

            $table->text('text')->nullable();

With that, I have relations like this in MessageThread:

    public function messages(): HasManyMerged
    {
        return $this->hasManyMerged(Message::class, ['from_to', 'to_from'], 'sender_number_receiver_number');
    }

It works fine, I mean I can get all messages (incoming, outgoing) from a message thread.

But I want to get a list of Threads, based on Messages.
Like, Thread which has most recent message should be on top, and least recent thread to the bottom.

I'm sure it's not the best solution for messaging, seems too hacky, but this is what I could come up with.
Please suggest some way to sort the threads, or maybe suggest something different all together.

Thanks.

Trying to install with the "^0" for Laravel 8 but getting error

What I did : composer require korridor/laravel-has-many-merged "^0"

What happened :

./composer.json has been updated
Running composer update korridor/laravel-has-many-merged
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires korridor/laravel-has-many-merged == 0.0.0.0, found korridor/laravel-has-many-merged[dev-feature/laravel_10, dev-main, 0.0.1, 0.0.2, 0.0.3, 1.0.0] but it does not match the constraint.


Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Your help would be greatly appreciated!

withCount doesn't work

Everything's Great ๐Ÿ‘Œ
"with" method is working but only problem i know is that "withCount" method doesn't working

merging two relation BelongsToMany and hasMany and returning relation

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

HasOne support?

It would be very nice to have HasOne support... nice work!

I'm a bit confused!

Hello, trying to use this for shops...

This is my model:

class Shop extends Model
{
    use HasFactory, SoftDeletes, HasManyMergedRelation;

    public function locations(): HasManyMerged
    {
        return $this->hasManyMerged(ShopAddress::class, ShopNumber::class);
    }

    public function addresses(): HasMany
    {
        return $this->hasMany(ShopAddress::class, 'shop_id');
    }

    public function numbers(): HasMany
    {
        return $this->hasMany(ShopNumber::class, 'shop_id');
    }
}

How would I make locations relationship work??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.