Session message on fail - Washing machine

This commit is contained in:
Anders 2020-08-04 08:31:14 +02:00
parent e8de894ae7
commit b59189eac0
2 changed files with 17 additions and 15 deletions

View File

@ -59,13 +59,16 @@ class WashingMachineController extends Controller
]);
$machine = new WashingMachine($data);
$saved = $machine->save();
if(!$saved){
return Response::detect("washing-machines.store");
}else{
$allMachines = WashingMachine::query()->where('name', '=', $request->name)->get();
// If there already is a washing machine with that name, then don't add it
if (count($allMachines) > 0)
return redirect()->route("washing-machines.store")->with('WashingNameExists', '<p><b>Der findes allerede en vaskemaskine med det navn!</b></p>');
else { // Else - Add it
$machine->save();
$machines = WashingMachine::query()->paginate($request->input("limit", 20));
return Response::detect("washing-machines.index", ['machines' => $machines]);
return redirect()->route("washing-machines.index", ['machines' => $machines]);
}
}
@ -114,19 +117,17 @@ class WashingMachineController extends Controller
$machine = WashingMachine::find($id);
$allMachines = WashingMachine::query()->where('name', '=', $request->name)->where('id', '!=', $id)->get();
// If there already is a washing machine with that name, then don't change it
if (count($allMachines) > 0)
return redirect()->route("washing-machines.store")->with('WashingNameExists', '<p><b>Der findes allerede en vaskemaskine med det navn!</b></p>');
else { // Else - Change the name
$machine->update($data);
$saved = $machine->save();
if(!$saved){
return Response::detect("washing-machines.update", [
"machine" => $machine
]);
} else {
$machine->save();
$machines = WashingMachine::query()->paginate($request->input("limit", 20));
return Response::detect("washing-machines.index", [
"machines" => $machines
]);
return redirect()->route("washing-machines.index", ["machines" => $machines]);
}
}

View File

@ -13,6 +13,7 @@
<div class="row align-items-center">
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('washing-machines.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Vaskemaskine</a>
</div>
{!! session()->get('WashingNameExists') !!}
<table class="tbl mt-2">
<tr>
<th>Navn</th>