function autoComplete($term) { // DB::table('medication') // ->where('name', 'LIKE', '%'.$term.'%') // ->take(5)->get(); return Medication::where('name', 'LIKE', '%' . $term . '%')->take(5) - get(); }
function saveMedications($name, $quantity) { $list = ['name' => $name, 'quantity' => $quantity]; try { $medication = Medication::where('name', '=', $name)->firstOrFail(); $medication->quantity += $quantity; $medication->save(); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { $medication = Medication::firstOrCreate($list); } }
/** * test for deleting * * @return void */ public function testDelete() { Medication::where('name', 'test1')->delete(); Medication::where('name', 'test2')->delete(); Medication::where('name', 'test3')->delete(); }