2020-06-09 07:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-07-01 09:38:09 +00:00
|
|
|
use App\WashingMachine;
|
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-06-09 07:05:07 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-06-24 06:23:15 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
2020-06-15 06:59:15 +00:00
|
|
|
use App\WashingReservation;
|
2020-07-01 09:38:09 +00:00
|
|
|
use Illuminate\View\View;
|
2020-06-09 07:05:07 +00:00
|
|
|
|
|
|
|
class WashingReservationController extends Controller
|
|
|
|
{
|
2020-06-30 08:04:06 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware([ "auth" ]);
|
|
|
|
|
|
|
|
$this->middleware([ "check.auth:washing.machine.reservation.list" ])->only("index");
|
|
|
|
$this->middleware([ "check.auth:washing.machine.reservation.show" ])->only("show");
|
|
|
|
$this->middleware([ "check.auth:washing.machine.reservation.create" ])->only("create", "store");
|
|
|
|
$this->middleware([ "check.auth:washing.machine.reservation.edit" ])->only("edit", "update");
|
|
|
|
$this->middleware([ "check.auth:washing.machine.reservation.delete" ])->only("delete");
|
|
|
|
}
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2020-06-15 06:59:15 +00:00
|
|
|
* @param Request $request
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return Application|Factory|View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-15 06:59:15 +00:00
|
|
|
public function index(Request $request)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-07-01 09:38:09 +00:00
|
|
|
$reservations = WashingReservation::query()->paginate($request->query("limit", 20));
|
2020-06-15 06:59:15 +00:00
|
|
|
|
2020-06-25 11:28:51 +00:00
|
|
|
return Response::detect("washing-reservations.index", [ "reservations" => $reservations]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return Application|Factory|View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-07-01 09:38:09 +00:00
|
|
|
$machines = WashingMachine::all();
|
|
|
|
return Response::detect("washing-reservations.create", [ 'machines' => $machines ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return Application|Factory|View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-15 06:59:15 +00:00
|
|
|
$data = $request->validate([
|
2020-07-01 09:38:09 +00:00
|
|
|
"time" => "required",
|
|
|
|
"machine" => "required"
|
2020-06-15 06:59:15 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$machineReservation = new WashingReservation($data);
|
|
|
|
$machineReservation->save();
|
|
|
|
|
2020-07-01 09:54:33 +00:00
|
|
|
$saved = $machineReservation->save();
|
|
|
|
|
|
|
|
if(!$saved){
|
|
|
|
return Response::detect("washing-reservations.store", [
|
|
|
|
"washing_reservation" => $machineReservation
|
|
|
|
]);
|
|
|
|
}else{
|
|
|
|
$reservations = WashingReservation::query()->paginate($request->input("limit", 20));
|
2020-07-01 09:56:44 +00:00
|
|
|
$machines = WashingMachine::all();
|
|
|
|
|
|
|
|
return Response::detect("washing-machines.index", ['reservations' => $reservations, 'machines' => $machines]);
|
2020-07-01 09:54:33 +00:00
|
|
|
}
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return Application|Factory|View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2020-06-15 06:59:15 +00:00
|
|
|
$machineReservation = WashingReservation::find($id);
|
|
|
|
|
2020-06-25 11:28:51 +00:00
|
|
|
return Response::detect("washing-reservations.show", [
|
2020-06-15 06:59:15 +00:00
|
|
|
"machineReservation" => $machineReservation
|
|
|
|
]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return Application|Factory|View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-07-01 09:38:09 +00:00
|
|
|
$reservation = WashingReservation::query()->find($id);
|
|
|
|
$machines = WashingMachine::all();
|
|
|
|
|
|
|
|
return Response::detect("washing-reservations.edit", ['washing_reservation' => $reservation, 'machines' => $machines ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return Application|Factory|View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-15 06:59:15 +00:00
|
|
|
$data = $request->validate([
|
2020-07-01 09:38:09 +00:00
|
|
|
"time" => "required",
|
|
|
|
"machine" => "required"
|
2020-06-15 06:59:15 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$machineReservation = WashingReservation::find($id);
|
|
|
|
|
|
|
|
$machineReservation->update($data);
|
|
|
|
|
2020-07-01 09:54:33 +00:00
|
|
|
$saved = $machineReservation->save();
|
2020-06-15 06:59:15 +00:00
|
|
|
|
2020-07-01 09:54:33 +00:00
|
|
|
if(!$saved){
|
|
|
|
return Response::detect("washing-reservations.update", [
|
|
|
|
"washing_reservation" => $machineReservation
|
|
|
|
]);
|
|
|
|
}else{
|
|
|
|
$reservations = WashingReservation::query()->paginate($request->input("limit", 20));
|
2020-07-01 09:56:44 +00:00
|
|
|
$machines = WashingMachine::all();
|
|
|
|
|
|
|
|
return Response::detect("washing-machines.index", ['reservations' => $reservations, 'machines' => $machines]);
|
2020-07-01 09:54:33 +00:00
|
|
|
}
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
2020-07-01 09:38:09 +00:00
|
|
|
* @return RedirectResponse
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-06-15 06:59:15 +00:00
|
|
|
$machineReservation = WashingReservation::find($id);
|
|
|
|
$machineReservation->delete();
|
|
|
|
|
2020-07-01 09:38:09 +00:00
|
|
|
$reservations = WashingReservation::query()->paginate( 20);
|
|
|
|
|
|
|
|
return redirect()->route("washing-reservations.index", [ "reservations" => $reservations]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
}
|