Laravel 如何为本文创建表和设计关系
我的应用程序上有旅游服务,每个旅游都有许多“必需文档”、“规则”、“服务”和…,我如何创建一个表来将每个旅游连接到它自己的选项!?顺便说一下,我不想为每个选项创建透视表。Laravel 如何为本文创建表和设计关系,laravel,laravel-5,orm,eloquent,laravel-5.8,Laravel,Laravel 5,Orm,Eloquent,Laravel 5.8,我的应用程序上有旅游服务,每个旅游都有许多“必需文档”、“规则”、“服务”和…,我如何创建一个表来将每个旅游连接到它自己的选项!?顺便说一下,我不想为每个选项创建透视表。 谢谢。您至少需要一个透视表,如“tour\u details”。在该表中,您将保存包含巡更id的“巡更id”,以及包含详细信息类型(规则、服务等)的“类型”,以及包含之前定义的类型id的“详细信息id” 例如: 表“巡演”: Schema::create('tour', function (Blueprint $tab
谢谢。您至少需要一个透视表,如“tour\u details”。在该表中,您将保存包含巡更id的“巡更id”,以及包含详细信息类型(规则、服务等)的“类型”,以及包含之前定义的类型id的“详细信息id” 例如: 表“巡演”:
Schema::create('tour', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
other table columns you need...
});
Schema::create('tour', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('tour_id');
$table->string('type');
$table->unsignedBigInteger('detail_id');
$table->foreign('tour_id')->references('id')->on('tours');
});
表“巡更详细信息”:
Schema::create('tour', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
other table columns you need...
});
Schema::create('tour', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('tour_id');
$table->string('type');
$table->unsignedBigInteger('detail_id');
$table->foreign('tour_id')->references('id')->on('tours');
});
这里,detail_id引用您选择的类型的id。例如:type='rules'和detail_id='21'表示它是表规则的ID21
如果没有更多信息,我们将无法为您提供太多帮助,但我希望这些信息足够有用,可以帮助您走上正轨。非常感谢,还有一个问题。如何在雄辩的模型中定义关系以检索细节?