Ekapp/skolehjem/app/Http/Controllers/WashingReservationControlle...

128 lines
3.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
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;
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");
}
/**
* Display a listing of the resource.
*
2020-06-15 06:59:15 +00:00
* @param Request $request
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
2020-06-15 06:59:15 +00:00
public function index(Request $request)
{
2020-06-15 06:59:15 +00:00
$reservations = WashingReservation::query()->paginate($request->query("page", 1));
return Response::detect("washing-reservations.index", [ "reservations" => $reservations]);
}
/**
* Show the form for creating a new resource.
*
2020-06-15 06:59:15 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
{
return Response::detect("washing-reservations.create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
2020-06-15 06:59:15 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function store(Request $request)
{
2020-06-15 06:59:15 +00:00
$data = $request->validate([
"time" => "required"
]);
$machineReservation = new WashingReservation($data);
$machineReservation->save();
return Response::detect("washing-reservations.store");
}
/**
* Display the specified resource.
*
* @param int $id
2020-06-15 06:59:15 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show($id)
{
2020-06-15 06:59:15 +00:00
$machineReservation = WashingReservation::find($id);
return Response::detect("washing-reservations.show", [
2020-06-15 06:59:15 +00:00
"machineReservation" => $machineReservation
]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
2020-06-15 06:59:15 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit($id)
{
return Response::detect("washing-reservations.edit");
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
2020-06-15 06:59:15 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function update(Request $request, $id)
{
2020-06-15 06:59:15 +00:00
$data = $request->validate([
"time" => "required"
]);
$machineReservation = WashingReservation::find($id);
$machineReservation->update($data);
$machineReservation->save();
return Response::detect("washing-reservations.edit", [
2020-06-15 06:59:15 +00:00
"washingReservation" => $machineReservation
]);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
2020-06-15 06:59:15 +00:00
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function destroy($id)
{
2020-06-15 06:59:15 +00:00
$machineReservation = WashingReservation::find($id);
$machineReservation->delete();
return Response::detect("washing-reservations.delete");
}
}