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