From da0e34fe8e6e71b0c5edb067d1b92b87d3355dd4 Mon Sep 17 00:00:00 2001 From: IsharaEkanayaka Date: Sat, 12 Oct 2024 18:36:35 +0530 Subject: [PATCH 1/5] create routes for taxonomy terms --- .../Models/TaxonomyTerm.php} | 14 ++--- .../Traits/Scope/TaxonomyTermsScope.php | 11 ---- .../Services/TaxonomyTermsService.php | 22 ------- ...troller.php => TaxonomyTermController.php} | 37 ++++++------ ...rmsFactory.php => TaxonomyTermFactory.php} | 9 +-- .../backend/taxonomy/terms/create.blade.php | 0 .../backend/taxonomy/terms/delete.blade.php | 0 .../backend/taxonomy/terms/edit.blade.php | 0 .../backend/taxonomy/terms/index.blade.php | 0 routes/backend/taxonomy.php | 58 +++++++++++++++++++ 10 files changed, 85 insertions(+), 66 deletions(-) rename app/Domains/{TaxonomyTerms/Models/TaxonomyTerms.php => Taxonomy/Models/TaxonomyTerm.php} (71%) delete mode 100644 app/Domains/TaxonomyTerms/Models/Traits/Scope/TaxonomyTermsScope.php delete mode 100644 app/Domains/TaxonomyTerms/Services/TaxonomyTermsService.php rename app/Http/Controllers/Backend/{TaxonomyTermsController.php => TaxonomyTermController.php} (60%) rename database/factories/{TaxonomyTermsFactory.php => TaxonomyTermFactory.php} (89%) create mode 100644 resources/views/backend/taxonomy/terms/create.blade.php create mode 100644 resources/views/backend/taxonomy/terms/delete.blade.php create mode 100644 resources/views/backend/taxonomy/terms/edit.blade.php create mode 100644 resources/views/backend/taxonomy/terms/index.blade.php diff --git a/app/Domains/TaxonomyTerms/Models/TaxonomyTerms.php b/app/Domains/Taxonomy/Models/TaxonomyTerm.php similarity index 71% rename from app/Domains/TaxonomyTerms/Models/TaxonomyTerms.php rename to app/Domains/Taxonomy/Models/TaxonomyTerm.php index 7daa09da..6a8d8dc3 100644 --- a/app/Domains/TaxonomyTerms/Models/TaxonomyTerms.php +++ b/app/Domains/Taxonomy/Models/TaxonomyTerm.php @@ -1,21 +1,19 @@ model = $taxonomyTerms; - } -} diff --git a/app/Http/Controllers/Backend/TaxonomyTermsController.php b/app/Http/Controllers/Backend/TaxonomyTermController.php similarity index 60% rename from app/Http/Controllers/Backend/TaxonomyTermsController.php rename to app/Http/Controllers/Backend/TaxonomyTermController.php index 69e8886a..2e74610e 100644 --- a/app/Http/Controllers/Backend/TaxonomyTermsController.php +++ b/app/Http/Controllers/Backend/TaxonomyTermController.php @@ -5,9 +5,9 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use App\Http\Controllers\Controller; -use App\Domains\TaxonomyTerms\Models\TaxonomyTerms; +use App\Domains\Taxonomy\Models\TaxonomyTerm; -class TaxonomyTermsController extends Controller +class TaxonomyTermController extends Controller { /** * Show the form for creating a new resource. @@ -17,7 +17,7 @@ class TaxonomyTermsController extends Controller public function create() { try{ - return view('backend.taxonomyTerms.create'); + return view('backend.taxonomy.terms.create'); }catch (\Exception $ex) { Log::error('Failed to load taxonomy terms creation page', ['error' => $ex->getMessage()]); return abort(500); @@ -36,15 +36,15 @@ public function store(Request $request) /** * Show the form for editing the specified resource. * - * @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms + * @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View */ - public function edit(TaxonomyTerms $taxonomyTerms) + public function edit(TaxonomyTerm $taxonomyTerm) { try{ - return view('backend.taxonomyTerms.edit', ['taxonomyTerms' => $taxonomyTerms]); + return view('backend.taxonomy.terms.edit', ['taxonomyTerm' => $taxonomyTerm]); }catch (\Exception $ex) { - Log::error('Failed to load taxonomy terms edit page', ['error' => $ex->getMessage()]); + Log::error('Failed to load taxonomy term edit page', ['error' => $ex->getMessage()]); return abort(500); } } @@ -52,40 +52,39 @@ public function edit(TaxonomyTerms $taxonomyTerms) * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms + * @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm * @return \Illuminate\Http\RedirectResponse */ - public function update(Request $request, TaxonomyTerms $taxonomyTerms) + public function update(Request $request, TaxonomyTerm $taxonomyTerm) { } /** * Confirm to delete the specified resource from storage. * - * @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms + * @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View */ - public function delete(TaxonomyTerms $taxonomyTerms) + public function delete(TaxonomyTerm $taxonomyTerm) { - return view('backend.taxonomyTerms.delete', compact('taxonomyTerms')); + return view('backend.taxonomy.terms.delete', compact('taxonomyTerm')); } /** * Remove the specified resource from storage. * - * @param \App\Domains\TaxonomyTerms\Models\TaxonomyTerms $taxonomyTerms + * @param \App\Domains\TaxonomyTerm\Models\TaxonomyTerm $taxonomyTerm * @return \Illuminate\Http\RedirectResponse|null */ - public function destroy(TaxonomyTerms $taxonomyTerms) + public function destroy(TaxonomyTerm $taxonomyTerm) { try { - $taxonomyTerms->delete(); - return redirect()->route('dashboard.taxonomyTerms.index')->with('Success', 'Taxonomy term was deleted !'); + $taxonomyTerm->delete(); + return redirect()->route('dashboard.taxonomy.terms.index')->with('Success', 'Taxonomy term was deleted !'); } catch (\Exception $ex) { - Log::error('Failed to delete taxonomy term', ['taxonomyTerms_id' => $taxonomyTerms->id, 'error' => $ex->getMessage()]); + Log::error('Failed to delete taxonomy term', ['taxonomyTerm_id' => $taxonomyTerm->id, 'error' => $ex->getMessage()]); return abort(500); } } -} - +} \ No newline at end of file diff --git a/database/factories/TaxonomyTermsFactory.php b/database/factories/TaxonomyTermFactory.php similarity index 89% rename from database/factories/TaxonomyTermsFactory.php rename to database/factories/TaxonomyTermFactory.php index cb580e2f..117d2123 100644 --- a/database/factories/TaxonomyTermsFactory.php +++ b/database/factories/TaxonomyTermFactory.php @@ -1,19 +1,16 @@ name('taxonomy.destroy'); + + //Taxonomy Term Routes + Route::group(['prefix' => 'taxonomy/{taxonomy}/terms'], function () { + + // Index (list terms for a taxonomy) + Route::get('/', function(){ + return view('backend.taxonomy.terms.index'); + })->name('taxonomy.terms.index') + ->breadcrumbs(function (Trail $trail, $taxonomy) { + $trail->push(__('Home'), route('dashboard.home')) + ->push(__('Taxonomy'), route('dashboard.taxonomy.index')) + ->push($taxonomy->name, route('dashboard.taxonomy.edit', $taxonomy)) + ->push(__('Terms'), route('dashboard.taxonomy.terms.index', $taxonomy)); + }); + + // Create (show form for creating a new term) + Route::get('/create', [TaxonomyTermController::class, 'create']) + ->name('taxonomy.terms.create') + ->breadcrumbs(function (Trail $trail, $taxonomy) { + $trail->push(__('Home'), route('dashboard.home')) + ->push(__('Taxonomy'), route('dashboard.taxonomy.index')) + ->push($taxonomy->name, route('dashboard.taxonomy.edit', $taxonomy)) + ->push(__('Create Term')); + }); + + // Store (store a new term in the taxonomy) + Route::post('/', [TaxonomyTermController::class, 'store']) + ->name('taxonomy.terms.store'); + + // Edit (show form for editing a term) + Route::get('/edit/{term}', [TaxonomyTermController::class, 'edit']) + ->name('taxonomy.terms.edit') + ->breadcrumbs(function (Trail $trail, $taxonomy, $term) { + $trail->push(__('Home'), route('dashboard.home')) + ->push(__('Taxonomy'), route('dashboard.taxonomy.index')) + ->push($taxonomy->name, route('dashboard.taxonomy.edit', $taxonomy)) + ->push(__('Edit Term')); + }); + + // Update (update a term in the taxonomy) + Route::put('/{term}', [TaxonomyTermController::class, 'update']) + ->name('taxonomy.terms.update'); + + // Delete (show confirmation for deleting a term) + Route::get('/delete/{term}', [TaxonomyTermController::class, 'delete']) + ->name('taxonomy.terms.delete') + ->breadcrumbs(function (Trail $trail, $taxonomy, $term) { + $trail->push(__('Home'), route('dashboard.home')) + ->push(__('Taxonomy'), route('dashboard.taxonomy.index')) + ->push($taxonomy->name, route('dashboard.taxonomy.edit', $taxonomy)) + ->push(__('Delete Term')); + }); + + // Destroy (delete a term from the taxonomy) + Route::delete('/{term}', [TaxonomyTermController::class, 'destroy']) + ->name('taxonomy.terms.destroy'); + }); }); From e1784c96a4b156697a37df458c9df2804d267e36 Mon Sep 17 00:00:00 2001 From: IsharaEkanayaka Date: Sun, 13 Oct 2024 12:23:39 +0530 Subject: [PATCH 2/5] feat: implement taxonomy create --- .../Backend/TaxonomyController.php | 21 +- app/Http/Livewire/Backend/TaxonomyTable.php | 4 +- resources/views/backend/layouts/app.blade.php | 60 ------ .../views/backend/taxonomy/create.blade.php | 95 +++++++++ .../taxonomy/index-table-row.blade.php | 20 +- .../backend/taxonomy_property_adder.blade.php | 196 ++++++++++++++++++ 6 files changed, 328 insertions(+), 68 deletions(-) create mode 100644 resources/views/components/backend/taxonomy_property_adder.blade.php diff --git a/app/Http/Controllers/Backend/TaxonomyController.php b/app/Http/Controllers/Backend/TaxonomyController.php index b8e97c5f..bcbed574 100644 --- a/app/Http/Controllers/Backend/TaxonomyController.php +++ b/app/Http/Controllers/Backend/TaxonomyController.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Auth; use App\Http\Controllers\Controller; use App\Domains\Taxonomy\Models\Taxonomy; @@ -31,7 +32,25 @@ public function create() */ public function store(Request $request) { - + $request->validate([ + 'code' => 'required|unique:taxonomies', + 'name' => 'required', + 'description' => 'required', + ]); + + try{ + $taxonomy = new Taxonomy(); + $taxonomy->code = $request->code; + $taxonomy->name = $request->name; + $taxonomy->description = $request->description; + $taxonomy->properties = $request->properties; + $taxonomy->created_by = Auth::user()->id; + $taxonomy->save(); + return redirect()->route('dashboard.taxonomy.index')->with('success', 'Taxonomy created successfully'); + }catch (\Exception $ex) { + Log::error('Failed to create taxonomy', ['error' => $ex->getMessage()]); + return abort(500); + } } /** * Show the form for editing the specified resource. diff --git a/app/Http/Livewire/Backend/TaxonomyTable.php b/app/Http/Livewire/Backend/TaxonomyTable.php index 9d4f3b43..0e2baae4 100644 --- a/app/Http/Livewire/Backend/TaxonomyTable.php +++ b/app/Http/Livewire/Backend/TaxonomyTable.php @@ -28,6 +28,8 @@ public function columns(): array ->sortable(), Column::make("Created at", "created_at") ->sortable(), + Column::make("Updated at", "updated_at") + ->sortable(), Column::make("Actions") ]; } @@ -39,7 +41,7 @@ public function query(): Builder public function rowView(): string { - return 'backend.taxonomies.index-table-row'; + return 'backend.taxonomy.index-table-row'; } } diff --git a/resources/views/backend/layouts/app.blade.php b/resources/views/backend/layouts/app.blade.php index 20851939..2eadad02 100644 --- a/resources/views/backend/layouts/app.blade.php +++ b/resources/views/backend/layouts/app.blade.php @@ -58,66 +58,6 @@ @stack('after-scripts') - - diff --git a/resources/views/backend/taxonomy/create.blade.php b/resources/views/backend/taxonomy/create.blade.php index e69de29b..d676dc7d 100644 --- a/resources/views/backend/taxonomy/create.blade.php +++ b/resources/views/backend/taxonomy/create.blade.php @@ -0,0 +1,95 @@ +@extends('backend.layouts.app') + +@section('title', __('Create Taxonomy')) + +@section('content') +
+ {!! Form::open([ + 'url' => route('dashboard.taxonomy.store'), + 'method' => 'post', + 'class' => 'container', + 'files' => true, + 'enctype' => 'multipart/form-data', + ]) !!} + + @csrf + + + Taxonomy : Create + + + +
+
+
Basic Configurations
+ +
+ {!! Form::label('code', 'Taxonomy Code*', ['class' => 'col-form-label']) !!} +
+
+
+ {!! Form::text('code', '', ['class' => 'form-control']) !!} + @error('code') + {{ $message }} + @enderror +
+
+ + +
+ {!! Form::label('name', 'Taxonomy Name*', ['class' => 'col-form-label']) !!} +
+ +
+
+ {!! Form::text('name', '', ['class' => 'form-control']) !!} + @error('name') + {{ $message }} + @enderror +
+ +
+ + +
+ {!! Form::label('description', 'Taxonomy Description*', ['class' => 'col-form-label']) !!} +
+ +
+
+ {!! Form::textarea('description', '', ['class' => 'form-control','style'=>'overflow:hidden;height: 100px;','oninput'=>"this.style.height = '100px';this.style.height = this.scrollHeight + 'px';"]) !!} + @error('description') + {{ $message }} + @enderror +
+ +
+
+
+ +
+
+
Properties
+ + {!! Form::hidden('properties', '', ['x-ref'=>'propertiesInput']) !!} +
+
+ + +
+ + + {!! Form::submit('Create', ['class' => 'btn btn-primary btn-w-150 float-right']) !!} + + +
+ + {!! Form::close() !!} +
+@endsection \ No newline at end of file diff --git a/resources/views/backend/taxonomy/index-table-row.blade.php b/resources/views/backend/taxonomy/index-table-row.blade.php index 3977af78..b5b65e83 100644 --- a/resources/views/backend/taxonomy/index-table-row.blade.php +++ b/resources/views/backend/taxonomy/index-table-row.blade.php @@ -1,6 +1,6 @@ - + {{ $row->code }} @@ -16,27 +16,35 @@ {{ User::find($row->updated_by)->name ?? 'N/A' }} + + {{ $row->created_at }} + + + + {{ $row->updated_at }} + +
- + {{-- - + --}} - + - + - + diff --git a/resources/views/components/backend/taxonomy_property_adder.blade.php b/resources/views/components/backend/taxonomy_property_adder.blade.php new file mode 100644 index 00000000..22c73fd1 --- /dev/null +++ b/resources/views/components/backend/taxonomy_property_adder.blade.php @@ -0,0 +1,196 @@ +
+ + +
+ + +
+ + + + +
    + +
+
From ff857437a6ae9f8b4d71abfc22a8751361e543bb Mon Sep 17 00:00:00 2001 From: Supun Dulara Date: Sun, 13 Oct 2024 22:29:28 +0530 Subject: [PATCH 3/5] implement taxonomy edit --- .../Backend/TaxonomyController.php | 36 +++++-- .../views/backend/taxonomy/edit.blade.php | 94 +++++++++++++++++++ .../backend/taxonomy_property_adder.blade.php | 2 +- 3 files changed, 125 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Backend/TaxonomyController.php b/app/Http/Controllers/Backend/TaxonomyController.php index bcbed574..dc5e80cc 100644 --- a/app/Http/Controllers/Backend/TaxonomyController.php +++ b/app/Http/Controllers/Backend/TaxonomyController.php @@ -35,7 +35,7 @@ public function store(Request $request) $request->validate([ 'code' => 'required|unique:taxonomies', 'name' => 'required', - 'description' => 'required', + 'description' => 'nullable', ]); try{ @@ -46,7 +46,7 @@ public function store(Request $request) $taxonomy->properties = $request->properties; $taxonomy->created_by = Auth::user()->id; $taxonomy->save(); - return redirect()->route('dashboard.taxonomy.index')->with('success', 'Taxonomy created successfully'); + return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy created successfully'); }catch (\Exception $ex) { Log::error('Failed to create taxonomy', ['error' => $ex->getMessage()]); return abort(500); @@ -60,13 +60,18 @@ public function store(Request $request) */ public function edit(Taxonomy $taxonomy) { - try{ - return view('backend.taxonomy.edit', ['taxonomy' => $taxonomy]); - }catch (\Exception $ex) { - Log::error('Failed to load taxonomy edit page', ['error' => $ex->getMessage()]); + try { + + return view('backend.taxonomy.edit', [ + 'taxonomy' => $taxonomy, + ]); + } catch (\Exception $ex) { + Log::error('Failed to load taxonomy edit page', ['error' => $ex->getMessage()]); return abort(500); } } + + /** * Update the specified resource in storage. * @@ -76,6 +81,25 @@ public function edit(Taxonomy $taxonomy) */ public function update(Request $request, Taxonomy $taxonomy) { + $data = $request->validate([ + 'code' => 'required', + 'name' => 'required', + 'description' => 'nullable', + + + ]); + + try{ + $taxonomy->update($data); + $taxonomy->updated_by = Auth::user()->id; + if ($request->properties != null) { + $taxonomy->properties = $request->properties;} + $taxonomy->save(); + return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy updated successfully'); + }catch (\Exception $ex) { + Log::error('Failed to update taxonomy', ['error' => $ex->getMessage()]); + return abort(500); + } } /** diff --git a/resources/views/backend/taxonomy/edit.blade.php b/resources/views/backend/taxonomy/edit.blade.php index e69de29b..a75a3fa3 100644 --- a/resources/views/backend/taxonomy/edit.blade.php +++ b/resources/views/backend/taxonomy/edit.blade.php @@ -0,0 +1,94 @@ +@extends('backend.layouts.app') + +@section('title', __('Edit Taxonomy')) + + +@section('content') +
+ {!! Form::model($taxonomy, [ + 'url' => route('dashboard.taxonomy.update', $taxonomy->id), + 'method' => 'PUT', + 'class' => 'container', + 'files' => true, + 'enctype' => 'multipart/form-data', + ]) !!} + + @csrf + + + Taxonomy : Edit + + + +
+
+
Basic Configurations
+ +
+ {!! Form::label('code', 'Taxonomy Code*', ['class' => 'col-form-label']) !!} +
+
+
+ {!! Form::text('code', null, ['class' => 'form-control']) !!} + @error('code') + {{ $message }} + @enderror +
+
+ + +
+ {!! Form::label('name', 'Taxonomy Name*', ['class' => 'col-form-label']) !!} +
+ +
+
+ {!! Form::text('name', null, ['class' => 'form-control']) !!} + @error('name') + {{ $message }} + @enderror +
+
+ + +
+ {!! Form::label('description', 'Taxonomy Description*', ['class' => 'col-form-label']) !!} +
+ +
+
+ {!! Form::textarea('description', null, ['class' => 'form-control','style'=>'overflow:hidden;height: 100px;','oninput'=>"this.style.height = '100px';this.style.height = this.scrollHeight + 'px';"]) !!} + @error('description') + {{ $message }} + @enderror +
+
+
+
+ +
+
+
Properties
+ + + {!! Form::hidden('properties', '', ['x-ref'=>'propertiesInput']) !!} +
+
+
+ + + {!! Form::submit('Update', ['class' => 'btn btn-primary btn-w-150 float-right']) !!} + + +
+ + {!! Form::close() !!} +
+@endsection diff --git a/resources/views/components/backend/taxonomy_property_adder.blade.php b/resources/views/components/backend/taxonomy_property_adder.blade.php index 22c73fd1..94ff77c7 100644 --- a/resources/views/components/backend/taxonomy_property_adder.blade.php +++ b/resources/views/components/backend/taxonomy_property_adder.blade.php @@ -1,5 +1,5 @@
+
{!! Form::open([ 'url' => route('dashboard.taxonomy.store'), 'method' => 'post', @@ -76,12 +70,10 @@
Properties
- - {!! Form::hidden('properties', '', ['x-ref'=>'propertiesInput']) !!} + + {!! Form::hidden('properties', '', ['x-model' => 'JSON.stringify(properties)']) !!}
- - diff --git a/resources/views/backend/taxonomy/edit.blade.php b/resources/views/backend/taxonomy/edit.blade.php index a75a3fa3..b882f4f4 100644 --- a/resources/views/backend/taxonomy/edit.blade.php +++ b/resources/views/backend/taxonomy/edit.blade.php @@ -2,16 +2,8 @@ @section('title', __('Edit Taxonomy')) - @section('content') -
+
{!! Form::model($taxonomy, [ 'url' => route('dashboard.taxonomy.update', $taxonomy->id), 'method' => 'PUT', @@ -76,9 +68,8 @@
Properties
- - {!! Form::hidden('properties', '', ['x-ref'=>'propertiesInput']) !!} + {!! Form::hidden('properties', '', ['x-model' => 'JSON.stringify(properties)']) !!}
diff --git a/resources/views/components/backend/taxonomy_property_adder.blade.php b/resources/views/components/backend/taxonomy_property_adder.blade.php index 94ff77c7..223a46d5 100644 --- a/resources/views/components/backend/taxonomy_property_adder.blade.php +++ b/resources/views/components/backend/taxonomy_property_adder.blade.php @@ -1,5 +1,5 @@
- +