Fixed Washing machine creation and editing
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
use App\WashingMachine;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class WashingMachineController extends Controller
|
||||
{
|
||||
@@ -24,11 +27,11 @@ class WashingMachineController 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)
|
||||
{
|
||||
$machines = WashingMachine::query()->paginate($request->query("page", 1));
|
||||
$machines = WashingMachine::query()->paginate($request->query("limit", 20));
|
||||
|
||||
return Response::detect("washing-machines.index", [ "machines" => $machines ]);
|
||||
}
|
||||
@@ -36,7 +39,7 @@ class WashingMachineController 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()
|
||||
{
|
||||
@@ -47,12 +50,12 @@ class WashingMachineController extends Controller
|
||||
* 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"
|
||||
"name" => "required"
|
||||
]);
|
||||
|
||||
$machine = new WashingMachine($data);
|
||||
@@ -65,7 +68,7 @@ class WashingMachineController 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,7 +83,7 @@ class WashingMachineController 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)
|
||||
{
|
||||
@@ -96,36 +99,43 @@ class WashingMachineController 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"
|
||||
"name" => "required"
|
||||
]);
|
||||
|
||||
$machine = WashingMachine::find($id);
|
||||
|
||||
$machine->update($data);
|
||||
|
||||
$machine->save();
|
||||
$saved = $machine->save();
|
||||
|
||||
return Response::detect("washing-machines.edit", [
|
||||
"machine" => $machine
|
||||
]);
|
||||
if(!$saved){
|
||||
return Response::detect("washing-machines.update", [
|
||||
"machine" => $machine
|
||||
]);
|
||||
}else{
|
||||
$machines = WashingMachine::query()->paginate($request->input("limit", 20));
|
||||
return Response::detect("washing-machines.index", [
|
||||
"machines" => $machines
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @param $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$machine = WashingMachine::find($id);
|
||||
$machine->delete();
|
||||
|
||||
return Response::detect("washing-machines.destroy");
|
||||
return Response::detect("washing-machines.delete");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WashingMachine extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user