Skip to content

Commit

Permalink
feat: update migration and config
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Sep 23, 2024
1 parent 661f3e2 commit 09d2f9f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ composer require cslant/laravel-like

## Configuration and Migrations

You can publish the configuration file with:
You can publish all the necessary configuration and migration files by running the following command:

```bash
php artisan vendor:publish --provider="Cslant\LaravelLike\LikeServiceProvider"
php artisan vendor:publish --provider="CSlant\LaravelLike\LikeServiceProvider"
```

After the configuration file has been published, you can run the migration:
Expand Down
12 changes: 12 additions & 0 deletions config/like.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@
'models' => [
'like' => \CSlant\LaravelLike\Models\Like::class,
],

'is_uuids' => false,

/*
* The table name for likes records.
*/
'likes_table' => 'likes',

/*
* User tables foreign key name.
*/
'user_foreign_key' => 'user_id',
];
11 changes: 9 additions & 2 deletions migrations/2024_09_23_163615_create_likes_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ public function up(): void
{
Schema::create('likes', function (Blueprint $table) {
$table->id();
$table->uuid();
$table->unsignedBigInteger('user_id');

if (config('like.is_uuids')) {
$table->uuid()->index();
}

$table->unsignedBigInteger(config('like.user_foreign_key'))->index();
$table->morphs('likeable');
$table->string('type')->default('like');

$table->unique(['user_id', 'model_id', 'model_type', 'type']);

$table->timestamps();
});
Expand Down

0 comments on commit 09d2f9f

Please sign in to comment.