From da97973679c1f9ce3bd60c2e5588176bb9869614 Mon Sep 17 00:00:00 2001 From: jk Date: Tue, 22 Jun 2021 12:28:48 +0100 Subject: [PATCH] adjuncts refactor mkI --- app/Http/Controllers/AdjunctController.php | 35 ++++++++++++-- resources/views/adjuncts.blade.php | 56 +--------------------- resources/views/adjuncts/create.blade.php | 28 +++++++++++ resources/views/adjuncts/edit.blade.php | 27 +++++++++++ resources/views/adjuncts/index.blade.php | 41 ++++++++++++++++ routes/web.php | 5 +- 6 files changed, 130 insertions(+), 62 deletions(-) diff --git a/app/Http/Controllers/AdjunctController.php b/app/Http/Controllers/AdjunctController.php index f1269b5..06779dc 100644 --- a/app/Http/Controllers/AdjunctController.php +++ b/app/Http/Controllers/AdjunctController.php @@ -16,7 +16,7 @@ class AdjunctController extends Controller public function index() { $adjuncts = Adjunct::orderBy('name')->get(); - return view('adjuncts')->with('adjuncts', $adjuncts); + return view('adjuncts.index')->with('adjuncts', $adjuncts); } public function store(Request $request){ @@ -28,14 +28,41 @@ class AdjunctController extends Controller // create project $adjunct = new Adjunct; - $lastID = Adjunct::orderBy('id','desc')->value('id'); + $lastID = Adjunct::orderBy('id','desc')->take(1)->value('id'); $adjunct->id = number_format($lastID) + 1; $adjunct->name = $request->input('name'); $adjunct->save(); - return redirect('/adjuncts')->with('success', 'Adjunct Added'); + return redirect('/adjuncts')->with('success', 'Adjunct Added!'); + } + public function edit($id){ + $adjunct = Adjunct::where('id', (int)$id)->first(); + return view('adjuncts.edit')->with('adjunct', $adjunct); } + public function update(Request $request, $id){ + // validation + $this->validate($request,[ + 'name' => 'required', + ]); -} + $adjunct = Adjunct::where('id', (int)$id)->first(); + $adjunct->name = $request->input('name'); + $adjunct->save(); + return redirect('/adjuncts')->with('success', 'Adjunct Updated!'); + } + public function create() + { + return view('adjuncts.create'); + } + public function destroy($id) + { + $adjunct = Adjunct::find($id); + $adjunct->delete(); + + return redirect('/adjuncts')->with('success', 'Adjunct deleted!'); + } + + +} diff --git a/resources/views/adjuncts.blade.php b/resources/views/adjuncts.blade.php index 6683449..9ede88a 100644 --- a/resources/views/adjuncts.blade.php +++ b/resources/views/adjuncts.blade.php @@ -1,60 +1,8 @@ @extends('layouts.app') @section('content') -
-
-
-
-@include('inc.navbar') -
Home -> {{ __('Adjunct List') }}Go Back
-
-@if (Auth::user()->isAdmin()) - -
-@endif - - - @include('inc.messages') - - @foreach ($adjuncts as $adjunct) - - - - @endforeach - -
{{$adjunct->name}}
-
-
-
-
-
- -