/** * Test to insert 3 * * @return void */ public function testAdd() { $list1 = ['quantity' => '23', 'name' => 'test1']; $list2 = ['quantity' => '15', 'name' => 'test2']; $list3 = ['quantity' => '45', 'name' => 'test3']; $testMedication = Medication::firstOrCreate($list1); $testMedication = Medication::firstOrCreate($list2); $testMedication = Medication::firstOrCreate($list3); }
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); } }