I have this method in a Model called Category, that brings all products from certain Category.
Model:
public function products()
{
return $this->hasMany(Product::class);
}
What I would like is put these products in order based on Array with IDs.
I tried this but didn't work:
public function products()
{
if ( !is_null($this->products_order)) {
$order = json_decode($this->products_order, true);
$products = $this->hasMany(Product::class)->orderBy('id',...$order);
return $products;
}
return $this->hasMany(Product::class);
}
$this->products_order
is a Array of IDs.