Skip to content

Commit

Permalink
Configable user foreign key.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Mar 7, 2018
1 parent 18e298a commit a6962d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config/follow.php
Expand Up @@ -25,6 +25,11 @@
*/
'users_table_primary_key' => 'id',

/*
* Foreign key of users table.
*/
'users_table_foreign_key' => 'user_id',

/*
* Table name of followable relations.
*/
Expand Down
7 changes: 4 additions & 3 deletions database/migrations/create_laravel_follow_tables.php
Expand Up @@ -20,13 +20,14 @@ class CreateLaravelFollowTables extends Migration
public function up()
{
Schema::create(config('follow.followable_table', 'followables'), function (Blueprint $table) {
$table->unsignedInteger('user_id');
$userForeignKey = config('follow.users_table_foreign_key', 'user_id');
$table->unsignedInteger($userForeignKey);
$table->unsignedInteger('followable_id');
$table->string('followable_type')->index();
$table->string('relation')->default('follow')->comment('folllow/like/subscribe/favorite/');
$table->string('relation')->default('follow')->comment('folllow/like/subscribe/favorite/upvote/downvote');
$table->timestamp('created_at');

$table->foreign('user_id')
$table->foreign($userForeignKey)
->references(config('follow.users_table_primary_key', 'id'))
->on(config('follow.users_table_name', 'users'))
->onUpdate('cascade')
Expand Down

0 comments on commit a6962d6

Please sign in to comment.