jeudi 16 juin 2016

Problems with laravel 5.1 relation

I have 3 tables with names Order - factor - products in order i have tracking code . and in factor i have product_id and order_id. How can I take Order Products ? :|

For example : order:where('trackingCode','HashCode')->ProductsInFactore()->get();

Order :

Schema::create('order', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('family');
        $table->string('email');
        $table->string('phone');
        $table->string('state');
        $table->string('city');
        $table->string('address');
        $table->string('PostalCode');
        $table->boolean('status')->default(0);
        $table->string('TrackingCode');
        $table->timestamps();
    });

Factore :

 Schema::create('factor', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('count');
        $table->integer('order_id')->unsigned();
        $table->integer('product_id')->unsigned();
        $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
        $table->foreign('order_id')->references('id')->on('order')->onDelete('cascade');
        $table->timestamps();
    });

And Products

Schema::create('products', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->longText('content');
        $table->string('colors');
        $table->tinyInteger('rate');
        $table->string('price');
        $table->string('discount')->default(0);
        $table->string('image');
        $table->string('url');
        $table->integer('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        $table->timestamps();
    });



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire