Fixed washing machine reservation, creation, edit and deletion
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\WashingMachine;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
use App\WashingReservation;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class WashingReservationController extends Controller
|
||||
{
|
||||
@@ -24,11 +29,11 @@ class WashingReservationController extends Controller
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$reservations = WashingReservation::query()->paginate($request->query("page", 1));
|
||||
$reservations = WashingReservation::query()->paginate($request->query("limit", 20));
|
||||
|
||||
return Response::detect("washing-reservations.index", [ "reservations" => $reservations]);
|
||||
}
|
||||
@@ -36,23 +41,25 @@ class WashingReservationController extends Controller
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Response::detect("washing-reservations.create");
|
||||
$machines = WashingMachine::all();
|
||||
return Response::detect("washing-reservations.create", [ 'machines' => $machines ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"time" => "required"
|
||||
"time" => "required",
|
||||
"machine" => "required"
|
||||
]);
|
||||
|
||||
$machineReservation = new WashingReservation($data);
|
||||
@@ -65,7 +72,7 @@ class WashingReservationController extends Controller
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
@@ -80,11 +87,14 @@ class WashingReservationController extends Controller
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return Response::detect("washing-reservations.edit");
|
||||
$reservation = WashingReservation::query()->find($id);
|
||||
$machines = WashingMachine::all();
|
||||
|
||||
return Response::detect("washing-reservations.edit", ['washing_reservation' => $reservation, 'machines' => $machines ]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,12 +102,13 @@ class WashingReservationController extends Controller
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"time" => "required"
|
||||
"time" => "required",
|
||||
"machine" => "required"
|
||||
]);
|
||||
|
||||
$machineReservation = WashingReservation::find($id);
|
||||
@@ -106,8 +117,8 @@ class WashingReservationController extends Controller
|
||||
|
||||
$machineReservation->save();
|
||||
|
||||
return Response::detect("washing-reservations.edit", [
|
||||
"washingReservation" => $machineReservation
|
||||
return Response::detect("washing-reservations.update", [
|
||||
"washing_reservation" => $machineReservation
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -115,13 +126,15 @@ class WashingReservationController extends Controller
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$machineReservation = WashingReservation::find($id);
|
||||
$machineReservation->delete();
|
||||
|
||||
return Response::detect("washing-reservations.delete");
|
||||
$reservations = WashingReservation::query()->paginate( 20);
|
||||
|
||||
return redirect()->route("washing-reservations.index", [ "reservations" => $reservations]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WashingReservation extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'time', 'machine'
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user