lundi 24 décembre 2018

laravel - get data out from many to many relations

ok straight to my question i have a many to many relation

public function products()
{

    return $this->belongsToMany(Product::class); // relation between books and categories

}

public function parts()
{

    return $this->belongsToMany(Part::class); // relation between books and categories

}

my migrations :

public function up()
{
    Schema::create('products', function (Blueprint $table) {

        $table->increments('id');
        $table->unsignedInteger('user_id');
        $table->string('link')->default('anohe.com');
        $table->string('pname')->default('product');
        $table->timestamps();
        $table->string('description',3000)->nullable();
        $table->string('smalldescription',500)->nullable();

    });
}

public function up()
{
    Schema::create('parts', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->timestamps();
    });
}

public function up()
{
    Schema::create('part_product', function (Blueprint $table) {
        $table->increments('id');
        $table->unsignedInteger('product_id');
        $table->unsignedInteger('part_id');
        $table->timestamps();

        $table
            ->foreign('product_id')
            ->references('id')
            ->on('products')
            ->onDelete('cascade');

        $table
            ->foreign('part_id')
            ->references('id')
            ->on('parts')
            ->onDelete('cascade');

    });

}

now i want to get products that have an special part_id i tried so many ways and i can explain what i did but that just be a waste of your time.so if anyone can tell me how to get products that have an special part_id pls help - ty -



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2GAAlwo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire