在Laravel中实现where子句find()

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

Use where()

$other_products = Product::where('id', '!=', $id)->get()->toArray();
$other_products = Product::where('id','!=',$id)->get();

Check https://laravel.com/docs/5.5/queries#where-clauses you can build queries using elequent models

Try:

$other_products = Product::where('id', '!=', $id)

OR

$other_products = Product::whereNotIn('id', [$id])

OR

$other_products = Product::where('id', '<>', $id)