【发布时间】:2020-09-10 06:09:16
【问题描述】:
我需要在表中创建关系。我在下面附上了我的表格。
这是我的类别模型。
class Category extends Model
{
public function products()
{
return $this->hasMany(Product::class);
}
public function categories_id() {
return $this->hasMany('category_id','parent_id');
}
public function parent_id() {
return $this->hasMany('category_id','parent_id');
}
}
在这里我如何关联 category_id 和 parent_id?
这是我的categories_table。
public function up()
{
Schema::create('categories', function (Blueprint $table)
{
$table->bigIncrements('id');
$table->unsignedBigInteger('parent_id')->nullable();
$table->string('cat_name')->nullable();
$table->string('cat_image_path')->nullable();
$table->timestamps();
});
}
【问题讨论】:
-
可能值得关注Nested sets。
标签: php laravel e-commerce