hootlex / laravel-friendships

This package gives Eloquent models the ability to manage their friendships.
MIT License
706 stars 151 forks source link

how do i use UUID #118

Closed antweny closed 5 years ago

antweny commented 5 years ago

I want to use UUID in this package.

On Friendship migration file should i change like this

Schema::create(config('friendships.tables.fr_pivot'), function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->morphs('sender');
            $table->morphs('recipient');
            $table->tinyInteger('status')->default(0);
            $table->timestamps();
        });

And on friendships groupd i changed like this

 Schema::create(config('friendships.tables.fr_groups_pivot'), function (Blueprint $table) {

            $table->uuid('friendship_id');
            $table->morphs('friend');
            $table->uuid('group_id');

            $table->foreign('friendship_id')
                ->references('id')
                ->on(config('friendships.tables.fr_pivot'))
                ->onDelete('cascade');

            $table->unique(['friendship_id', 'friend_id', 'friend_type', 'group_id'], 'unique');

        });

how do i deal with morphs data type....

TechTailor commented 5 years ago

Hey, are you eliminating id's from your user's table entirely? Why do you wan't to use UUID instead? Just trying to understand the use case and benefit of it here?

7KiLL commented 5 years ago

Morph method is simply shortcut for {name}_id and {name}_type. But for id it takes bigInteger. We need uuid field type.

Schema::create(config('friendships.tables.fr_pivot'), function (Blueprint $table) {
            $table->increments('id');
            $table->string('sender_type');
            $table->uuid('sender_id');
            $table->string('recipient_type');
            $table->uuid('recipient_id');
            $table->tinyInteger('status')->default(0);
            $table->timestamps();
        });

and

Schema::create(config('friendships.tables.fr_groups_pivot'), function (Blueprint $table) {

            $table->integer('friendship_id')->unsigned();
            $table->string('friend_type');
            $table->uuid('friend_id');
            $table->integer('group_id')->unsigned();

            $table->foreign('friendship_id')
                ->references('id')
                ->on(config('friendships.tables.fr_pivot'))
                ->onDelete('cascade');

            $table->unique(['friendship_id', 'friend_id', 'friend_type', 'group_id'], 'unique');

        });