mardi 23 octobre 2018

how to many to many relationship query in laravel

I use laravel 5.6

I have problem in many to many relation query .

I have 2 table . Order & Cart

//------- Cart Model -------------
class Cart extends Model
{

    public function order()
    {
        return $this->belongsToMany(Order::class);
    }

}

and Order model :

class Order extends Model
{

    public function carts(){

        return $this->belongsToMany(Cart::class);
    }


}

and Cart Migration :

public function up()
{
    Schema::create('carts', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->nullable();
        $table->integer('price')->nullable();
        $table->integer('pass')->default(0);

    });
}

now , how to get orders that their Pass field are in Cart = 1 in controller ?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire