diff --git a/skolehjem/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index 27d1cde..d45b482 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -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"); } } diff --git a/skolehjem/app/WashingMachine.php b/skolehjem/app/WashingMachine.php index 3da7e25..634448d 100644 --- a/skolehjem/app/WashingMachine.php +++ b/skolehjem/app/WashingMachine.php @@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model; class WashingMachine extends Model { - // + protected $fillable = [ + 'name' + ]; } diff --git a/skolehjem/resources/views/admin/washing-machines/delete.blade.php b/skolehjem/resources/views/admin/washing-machines/delete.blade.php index 9efdfdf..27d681e 100644 --- a/skolehjem/resources/views/admin/washing-machines/delete.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/delete.blade.php @@ -6,7 +6,7 @@ @endsection @section("path") - Fjern Vaskemaskine / + Fjern Vaskemaskine / @endsection @section("content") diff --git a/skolehjem/resources/views/admin/washing-machines/edit.blade.php b/skolehjem/resources/views/admin/washing-machines/edit.blade.php index ea595fc..7e080d5 100644 --- a/skolehjem/resources/views/admin/washing-machines/edit.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/edit.blade.php @@ -6,14 +6,15 @@ @endsection @section("path") - Rediger Vaskemaskiner / + Rediger Vaskemaskiner / @endsection @section("content") -
+ $machine]) }}"> @csrf + @method("put") - - + +
@endsection diff --git a/skolehjem/resources/views/admin/washing-machines/index.blade.php b/skolehjem/resources/views/admin/washing-machines/index.blade.php index 1b2be54..5242a0c 100644 --- a/skolehjem/resources/views/admin/washing-machines/index.blade.php +++ b/skolehjem/resources/views/admin/washing-machines/index.blade.php @@ -21,9 +21,9 @@ @foreach($machines as $machine) - {Navn} - Update -
$machine ]) }}" class="w-100 nostyle"> + {{$machine->name}} + Update + @csrf @method("delete")