[英]Laravel Migration for Followers / Following
我正在为用户关注者设置迁移。 我想用它来检查一个用户是否在关注另一个用户,以及是否允许他查看发布者的帖子并对其发表评论。
我根据此示例进行此操作:
我这样写:
class CreateFollowersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('followers', function (Blueprint $table) {
$table->unsignedInteger('publisher_id')->nullable()->unsigned();
$table->unsignedInteger('follower_id')->nullable()->unsigned();
$table->boolean('enable_follow')->default('1')->unsigned();
$table->timestamps();
$table->foreign('publisher_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->foreign('follower_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
schema::drop('followers');
}
}
该表的用法如下:
1)用户可以(单击)关注发布者,因此可以按照表成为关注者。 示例Publisher_id = 1; Follower_id = 2; enable_follow = 1;
Publisher_id = 1; Follower_id = 2; enable_follow = 1;
ID为2的用户现在紧随用户ID为1之后,可以在Feed中看到该用户的帖子,例如在twitter中。 当enable_follow设置为1时,使用户能够查看帖子并评论这些帖子
2)发布者可以禁止用户查看或评论他的帖子,例如Publisher_id = 1; Follower_id = 2; enable_follow = 0;
Publisher_id = 1; Follower_id = 2; enable_follow = 0;
问题:哪些用户可以看到( 在搜索帖子之后,不在提要中 )并评论其他用户的帖子? 答:每个用户,除非发布者在收到不需要的评论后决定禁止发布不需要的评论的用户。
在发表评论之前,两个用户之间的关注者表中根本没有任何关系。 该关系是在发布者禁止用户之后创建的,并且类似于示例2中的Publisher_id = 1; Follower_id = 2; enable_follow = 0;
Publisher_id = 1; Follower_id = 2; enable_follow = 0;
因此,基本上'follower_id'实际上既充当关注者又充当评论者。
我想说这个架构应该能够处理您正在寻找的功能。
我唯一不了解的是可为空的外键。 我不确定是否有必要使它们为可空值,或者如果一个为空则意味着什么。 如果将它们设置为可空值,或者如果有可能,也可能不会损害它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.