【发布时间】:2018-06-07 07:52:10
【问题描述】:
我需要一些逻辑帮助,我有一个文章表和一个 cmets 表。当用户 cmets 我将其存储在表中时:
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->string('user_id');
$table->string('comment');
$table->integer('article_id');
$table->timestamps();
});
}
我不知道是否需要添加另一个表(例如user_comments)来建立这种关系,这对我来说实际上听起来很愚蠢,但我在这里遇到的问题是我得到的 cmets基本查询,例如:
$comments = DB::select("Select * from comments where article_id=$articleID");
但是我很难展示username 之类的东西,所以我需要一个简单的关系,有人知道如何实现它吗?
【问题讨论】:
标签: mysql laravel laravel-5.4 relationship