Reputation: 1230
Here is my code:
public function order($id)
{
$product = Product::find($id);
$other_products = Product::find($id)->toArray();
return view('products.order',['product'=>$product,'other'=>$other_products]);
}
So my question is how can i exclude $product
from the $other_products
query, more like SELECT * FROM table WHERE product != $id
Upvotes: 1
Views: 854
Reputation: 133
Try:
$other_products = Product::where('id', '!=', $id)
OR
$other_products = Product::whereNotIn('id', [$id])
OR
$other_products = Product::where('id', '<>', $id)
Upvotes: 3
Reputation: 2523
$other_products = Product::where('id','!=',$id)->get();
Check https://laravel.com/docs/5.5/queries#where-clauses you can build queries using elequent models
Upvotes: 0
Reputation: 9853
Use where()
$other_products = Product::where('id', '!=', $id)->get()->toArray();
Upvotes: 2