diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index 992459f..895f3df 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -17,8 +17,10 @@ public function index() { $this->authorize('viewAny', Category::class); - return View::make('categories.index', - ['categories' => Category::all()]); + return View::make('categories.index', [ + 'categories' => Category::all(), + 'trashedCategories' => Category::onlyTrashed()->get() + ]); } public function create() @@ -42,6 +44,8 @@ public function show(Category $category) { $this->authorize('view', $category); + $category->load('programs'); + return View::make('categories.show', ['category' => $category]); } @@ -54,11 +58,18 @@ public function edit(Category $category) public function update(CategoryRequest $request, Category $category) { - $this->authorize('update', $category); + if ($request->has('restore')) { + $this->authorize('restore', $category); - $category->update($request->validated()); + $category->restore(); + $request->session()->flash('status', 'Category restored!'); + } else { + $this->authorize('update', $category); + + $category->update($request->validated()); + $request->session()->flash('status', 'Category updated!'); + } - $request->session()->flash('status', 'Category updated!'); return Redirect::route('categories.index'); } diff --git a/app/Http/Controllers/ProgramController.php b/app/Http/Controllers/ProgramController.php index 440c5df..8d962a6 100644 --- a/app/Http/Controllers/ProgramController.php +++ b/app/Http/Controllers/ProgramController.php @@ -5,6 +5,7 @@ use App\Http\Requests\ProgramRequest; use App\Models\Program; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; +use Illuminate\Support\Facades\View; class ProgramController extends Controller { @@ -14,7 +15,7 @@ public function index() { $this->authorize('viewAny', Program::class); - return Program::all(); + return View::make('programs.index', ['programs' => Program::all()]); } public function store(ProgramRequest $request) diff --git a/app/Http/Requests/CategoryRequest.php b/app/Http/Requests/CategoryRequest.php index 9f35641..1ecfcb9 100644 --- a/app/Http/Requests/CategoryRequest.php +++ b/app/Http/Requests/CategoryRequest.php @@ -10,15 +10,22 @@ class CategoryRequest extends FormRequest public function rules(): array { return [ - 'name' => ['required'], + 'name' => ['sometimes', 'required', 'string'], + 'restore' => ['sometimes', 'required', 'boolean'] ]; } public function authorize(): bool { + if ($this->request->has('restore')) { + return $this->user()->can('restore', $this->route('category')); + } + if ($this->routeIs('categories.store')) { return $this->user()->can('create', Category::class); - } elseif ($this->routeIs('categories.update')) { + } + + if ($this->routeIs('categories.update')) { return $this->user()->can('update', $this->route('category')); } diff --git a/app/Policies/CategoryPolicy.php b/app/Policies/CategoryPolicy.php index 4ff52c9..f2ac1c8 100644 --- a/app/Policies/CategoryPolicy.php +++ b/app/Policies/CategoryPolicy.php @@ -11,12 +11,12 @@ class CategoryPolicy { use HandlesAuthorization; - public function viewAny(User $user): bool + public function viewAny(?User $user): bool { return true; } - public function view(User $user, Category $category): bool + public function view(?User $user, Category $category): bool { return true; } diff --git a/resources/views/categories/index.blade.php b/resources/views/categories/index.blade.php index 3b88ed2..86b0d13 100644 --- a/resources/views/categories/index.blade.php +++ b/resources/views/categories/index.blade.php @@ -1,64 +1,112 @@ - -
- - - - - - - - - @foreach ($categories as $category) - - - + + @endforeach + +
CategoryActions
{{ $category->name }} - - View - + + @auth + + Active + Deleted + + @endauth - @auth +
+
+ + + + + @auth + + @endauth + + + + @foreach ($categories as $category) + + + @auth + + @endauth + + @endforeach + +
CategoryActions
- Edit + {{ $category->name }} + + + Edit + +
+ @csrf + @method('DELETE') + + + Delete + +
+
+
+
+ +
+
+ + + + + + + + + @foreach ($trashedCategories as $category) + + + - - @endforeach - -
CategoryActions
{{ $category->name }}
@csrf - @method('DELETE') + @method('PATCH') + + - Delete + Restore
- @endauth -
+
+
- @auth New @endauth diff --git a/resources/views/categories/show.blade.php b/resources/views/categories/show.blade.php index 2ebb5ca..d22bc37 100644 --- a/resources/views/categories/show.blade.php +++ b/resources/views/categories/show.blade.php @@ -1,5 +1,9 @@ + @foreach ($category->programs as $program) + {{ $program->name }} + @endforeach + All diff --git a/resources/views/components/layout/navigation.blade.php b/resources/views/components/layout/navigation.blade.php index 9e24fe9..edebeaf 100644 --- a/resources/views/components/layout/navigation.blade.php +++ b/resources/views/components/layout/navigation.blade.php @@ -46,10 +46,7 @@ class="window" 'tab', +]) + + diff --git a/resources/views/components/tablist/tablist.blade.php b/resources/views/components/tablist/tablist.blade.php new file mode 100644 index 0000000..d2745f4 --- /dev/null +++ b/resources/views/components/tablist/tablist.blade.php @@ -0,0 +1,3 @@ + + {{ $slot }} + diff --git a/resources/views/programs/index.blade.php b/resources/views/programs/index.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/routes/web.php b/routes/web.php index cd2e4c0..45aea03 100755 --- a/routes/web.php +++ b/routes/web.php @@ -27,4 +27,4 @@ Route::resources([ 'categories' => CategoryController::class, 'programs' => ProgramController::class -]); +], ['trashed' => []]);