【发布时间】:2020-07-09 09:25:30
【问题描述】:
我是初学者网络开发人员。我在 Laravel 7 中制作我的项目。
我有这个代码:
迁移:
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name', 155);
$table->string('title', 155);
$table->string('description', 155)->nullable();
$table->string('keywords', 155)->nullable();
$table->longText('content')->nullable();
$table->string('delivery_time', 155)->nullable();
$table->string('small_description', 155)->nullable();
$table->smallInteger('vat_id')->unsigned()->default(1);
$table->foreign('vat_id')->references('id')->on('vat');
$table->bigInteger('category_id')->unsigned()->default(0);
//$table->foreign('category_id')->references('id')->on('categories');
$table->char('enable', 1)->default(0);
$table->char('product_type', 1)->default(0);
$table->string('slug', 160)->nullable();
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
Schema::create('selected_product_features', function (Blueprint $table) {
$table->id();
$table->bigInteger('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->bigInteger('feature_id')->unsigned();
$table->foreign('feature_id')->references('id')->on('product_features')->onDelete('cascade');
$table->string('key', 50);
$table->text('description')->nullable();;
$table->timestamps();
});
我需要显示 selected_product_features key = "form-2" 和 description = 1 中的所有产品。
我该怎么做?
【问题讨论】:
-
您有 Product 和 SelectedProductFeature 模型吗?您是否定义了从 Product 到 SelectedProductFeature 的关系?
-
请遵循迁移文档。这样的解释是有的。 laravel.com/docs/7.x/migrations#introduction
标签: php laravel laravel-5 laravel-7