stationFuelPrices = new StationFuelPrices; $uuid = new UuidHelper; $this->stationFuelPrices->fuel_price_uuid = $uuid->generate_uuid1(); $this->stationFuelPrices->station_id = $station_id; $this->stationFuelPrices->fuel_code = $data['fuel_code']; $this->stationFuelPrices->fuel_name = $data['fuel_name']; $this->stationFuelPrices->price = $data['price']; if ($this->stationFuelPrices->save()) { return true; } else { return false; } } public function getByField($data, $relationship = null, $order_by = null) { if($relationship) { $this->stationFuelPrices = StationFuelPrices::with($relationship); } else $this->stationFuelPrices = new StationFuelPrices; if(count($data)) { foreach ($data as $field => $value) { $this->stationFuelPrices = $this->stationFuelPrices->where($field,$value); } } if($order_by != null) $this->stationFuelPrices->orderBy($order_by['field'],$order_by['value']); return $this->stationFuelPrices->get(); } public function update_price($uuid,$price) { $this->stationFuelPrices = StationFuelPrices::where('fuel_price_uuid',$uuid)->first(); if($this->stationFuelPrices) { $this->stationFuelPrices->price = $price; if ($this->stationFuelPrices->save()) { return $this->stationFuelPrices; } } return false; } public function delete($station_id,$ids) { $this->stationFuelPrices = StationFuelPrices::where('station_id',$station_id) ->whereNotIn('fuel_code',$ids) ->update([ 'is_active' => 0 ]); if($this->stationFuelPrices) return true; else return false; } }