Laravel Eloquent orWhere Query

后端 未结 4 1559
悲哀的现实
悲哀的现实 2021-01-17 18:05

Can someone show me how to write this query in Eloquent?

SELECT * FROM `projects` WHERE `id`=\'17\' OR `id`=\'19\'

I am thinking

         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 18:49

    public function getSearchProducts($searchInput)
        {
            $products = Cache::rememberForever('getSearchProductsWithDiscountCalculationproducts',  function () {
                return DB::table('products_view')->get();
            });
    
            $searchProducts = $products->filter(function ($item) use($searchInput)  {
                return preg_match('/'.$searchInput.'/i', $item->productName) || preg_match('/'.$searchInput.'/i', $item->searchTags) ;
            });
    
             $response = ["status" => "Success", "data" => $searchProducts ];
            return response(json_encode($response), 200, ["Content-Type" => "application/json"]);
        }
    

    use filter functionality for any customize situations.

提交回复
热议问题