I'm trying to translate a SQL
to Eloquent
, where it gets an id ( $myid
) and returns the clothes combinations, clothes
and I have another table combinations_clothes
and in this case I have a relation many to many
.
The combinations_clothes
table consists of the following:
Schema::create('combinations_clothes', function (Blueprint $table)
{
$table->increments('id');
$table->integer('clothe_id')->unsigned();
$table->foreign('clothe_id')->references('id')
->on('clothes')->onDelete('cascade');
$table->integer('combination_id')->unsigned();
$table->foreign('combination_id')->references('id')
->on('clothes')->onDelete('cascade');
}
To do this, I created a SQL
to return the clothes combinations ( $myid
), regardless of the order in which it was attached, ie clothe_id = 2
and combination_id = 5
. even if it has been written clothe_id = 5
and combination_id = 2
and SQL is as follows:
select 'clothes.id´ from clothes join 'combinations_clothes´
where (clothes.id = clothe_id or clothes.id = combination_id)
and clothes.id <> $myid
However, you had to pass this SQL to Eloquent
of Laravel
. Someone can help me?