jeudi 9 juillet 2020

Displaying records based on a relationship table in Laravel

I am beginner web developer. I make my project in Laravel 7.

I have this code:

Migration:

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();
        });

I need show all products where in selected_product_features key = "form-2" and description = 1.

How can I make it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire