Session message on fail - Washing machine
This commit is contained in:
parent
e8de894ae7
commit
b59189eac0
|
@ -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);
|
||||
|
||||
$machine->update($data);
|
||||
|
||||
$saved = $machine->save();
|
||||
$allMachines = WashingMachine::query()->where('name', '=', $request->name)->where('id', '!=', $id)->get();
|
||||
|
||||
if(!$saved){
|
||||
return Response::detect("washing-machines.update", [
|
||||
"machine" => $machine
|
||||
]);
|
||||
} else {
|
||||
// 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);
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue