diff --git a/app/Domains/Taxonomy/Models/TaxonomyTerm.php b/app/Domains/Taxonomy/Models/TaxonomyTerm.php index c885edf..1880f69 100644 --- a/app/Domains/Taxonomy/Models/TaxonomyTerm.php +++ b/app/Domains/Taxonomy/Models/TaxonomyTerm.php @@ -91,6 +91,15 @@ public function getMetadata($code) return null; } + protected static function boot() + { + parent::boot(); + + static::deleting(function ($taxonomyTerm) { + $taxonomyTerm->children()->delete(); + }); + } + public static function getHierarchicalPath($id) { $term = TaxonomyTerm::find($id); @@ -139,4 +148,4 @@ protected static function newFactory() { return TaxonomyTermFactory::new(); } -} +} \ No newline at end of file diff --git a/app/Http/Controllers/Backend/TaxonomyController.php b/app/Http/Controllers/Backend/TaxonomyController.php index 9fb98a0..04760da 100644 --- a/app/Http/Controllers/Backend/TaxonomyController.php +++ b/app/Http/Controllers/Backend/TaxonomyController.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Auth; use App\Http\Controllers\Controller; use App\Domains\Taxonomy\Models\Taxonomy; +use App\Domains\Taxonomy\Models\TaxonomyTerm; class TaxonomyController extends Controller { @@ -115,7 +116,8 @@ public function update(Request $request, Taxonomy $taxonomy) */ public function delete(Taxonomy $taxonomy) { - return view('backend.taxonomy.delete', compact('taxonomy')); + $terms = TaxonomyTerm::where('taxonomy_id', $taxonomy->id)->get(); + return view('backend.taxonomy.delete', compact('taxonomy', 'terms')); } @@ -128,6 +130,12 @@ public function delete(Taxonomy $taxonomy) public function destroy(Taxonomy $taxonomy) { try { + $terms = TaxonomyTerm::where('taxonomy_id', $taxonomy->id)->get(); + if ($terms->count() > 0) { + return redirect()->route('dashboard.taxonomy.index') + ->withErrors('Can not delete the Taxonomy as it already has associated Taxonomy Terms. Please reassign or delete those first.'); + } + $taxonomy->delete(); return redirect()->route('dashboard.taxonomy.index')->with('Success', 'Taxonomy was deleted !'); } catch (\Exception $ex) { diff --git a/composer.lock b/composer.lock index d4559bc..969b482 100644 --- a/composer.lock +++ b/composer.lock @@ -1512,16 +1512,16 @@ }, { "name": "guzzlehttp/promises", - "version": "2.0.3", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8" + "reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", - "reference": "6ea8dd08867a2a42619d65c3deb2c0fcbf81c8f8", + "url": "https://api.github.com/repos/guzzle/promises/zipball/f9c436286ab2892c7db7be8c8da4ef61ccf7b455", + "reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455", "shasum": "" }, "require": { @@ -1575,7 +1575,7 @@ ], "support": { "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.3" + "source": "https://github.com/guzzle/promises/tree/2.0.4" }, "funding": [ { @@ -1591,7 +1591,7 @@ "type": "tidelift" } ], - "time": "2024-07-18T10:29:17+00:00" + "time": "2024-10-17T10:06:22+00:00" }, { "name": "guzzlehttp/psr7", @@ -8023,16 +8023,16 @@ }, { "name": "barryvdh/reflection-docblock", - "version": "v2.1.1", + "version": "v2.1.2", "source": { "type": "git", "url": "https://github.com/barryvdh/ReflectionDocBlock.git", - "reference": "e6811e927f0ecc37cc4deaa6627033150343e597" + "reference": "bba116ba9d5794fbf12e03ed40f10804e51acf76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/ReflectionDocBlock/zipball/e6811e927f0ecc37cc4deaa6627033150343e597", - "reference": "e6811e927f0ecc37cc4deaa6627033150343e597", + "url": "https://api.github.com/repos/barryvdh/ReflectionDocBlock/zipball/bba116ba9d5794fbf12e03ed40f10804e51acf76", + "reference": "bba116ba9d5794fbf12e03ed40f10804e51acf76", "shasum": "" }, "require": { @@ -8069,9 +8069,9 @@ } ], "support": { - "source": "https://github.com/barryvdh/ReflectionDocBlock/tree/v2.1.1" + "source": "https://github.com/barryvdh/ReflectionDocBlock/tree/v2.1.2" }, - "time": "2023-06-14T05:06:27+00:00" + "time": "2024-10-16T11:06:28+00:00" }, { "name": "brianium/paratest", @@ -10187,16 +10187,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.32.0", + "version": "1.33.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4" + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6ca22b154efdd9e3c68c56f5d94670920a1c19a4", - "reference": "6ca22b154efdd9e3c68c56f5d94670920a1c19a4", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", "shasum": "" }, "require": { @@ -10228,9 +10228,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.32.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" }, - "time": "2024-09-26T07:23:32+00:00" + "time": "2024-10-13T11:25:22+00:00" }, { "name": "phpunit/php-code-coverage", @@ -11190,17 +11190,17 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "c3c55a0f6643119fa8699577cc83ca6256d98ab5" + "reference": "2db4b93f047a03be06ec0a890d252e1c8c635f74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/c3c55a0f6643119fa8699577cc83ca6256d98ab5", - "reference": "c3c55a0f6643119fa8699577cc83ca6256d98ab5", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/2db4b93f047a03be06ec0a890d252e1c8c635f74", + "reference": "2db4b93f047a03be06ec0a890d252e1c8c635f74", "shasum": "" }, "conflict": { "3f/pygmentize": "<1.2", - "admidio/admidio": "<4.3.10", + "admidio/admidio": "<4.3.12", "adodb/adodb-php": "<=5.20.20|>=5.21,<=5.21.3", "aheinze/cockpit": "<2.2", "aimeos/ai-admin-graphql": ">=2022.04.1,<2022.10.10|>=2023.04.1,<2023.10.6|>=2024.04.1,<2024.04.6", @@ -11709,7 +11709,7 @@ "rap2hpoutre/laravel-log-viewer": "<0.13", "react/http": ">=0.7,<1.9", "really-simple-plugins/complianz-gdpr": "<6.4.2", - "redaxo/source": "<=5.15.1", + "redaxo/source": "<=5.17.1", "remdex/livehelperchat": "<4.29", "reportico-web/reportico": "<=8.1", "rhukster/dom-sanitizer": "<1.0.7", @@ -11783,7 +11783,7 @@ "subhh/libconnect": "<7.0.8|>=8,<8.1", "sukohi/surpass": "<1", "sulu/form-bundle": ">=2,<2.5.3", - "sulu/sulu": "<1.6.44|>=2,<2.6.5", + "sulu/sulu": "<1.6.44|>=2,<2.5.21|>=2.6,<2.6.5", "sumocoders/framework-user-bundle": "<1.4", "superbig/craft-audit": "<3.0.2", "swag/paypal": "<5.4.4", @@ -12013,7 +12013,7 @@ "type": "tidelift" } ], - "time": "2024-10-11T18:06:00+00:00" + "time": "2024-10-18T15:05:15+00:00" }, { "name": "sebastian/cli-parser", @@ -13383,5 +13383,5 @@ "php": "^7.4|^8.0" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/resources/views/backend/taxonomy/delete.blade.php b/resources/views/backend/taxonomy/delete.blade.php index 187e85b..78e5fb8 100644 --- a/resources/views/backend/taxonomy/delete.blade.php +++ b/resources/views/backend/taxonomy/delete.blade.php @@ -13,18 +13,34 @@

Are you sure you want to delete "{{ $taxonomy->name }}" ?

-
- {!! Form::open([ - 'url' => route('dashboard.taxonomy.destroy', compact('taxonomy')), - 'method' => 'delete', - 'class' => 'container', - ]) !!} + @if ($terms->count() > 0) +

The following terms are linked to this Taxonomy. Deletion is not permitted until these terms are + reassigned or deleted.

+ Back - {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!} + @else +
+ {!! Form::open([ + 'url' => route('dashboard.taxonomy.destroy', compact('taxonomy')), + 'method' => 'delete', + 'class' => 'container', + ]) !!} + + Back + {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} +
+ @endif - {!! Form::close() !!} -
diff --git a/resources/views/backend/taxonomy/terms/delete.blade.php b/resources/views/backend/taxonomy/terms/delete.blade.php index 3581dbf..ff1c125 100644 --- a/resources/views/backend/taxonomy/terms/delete.blade.php +++ b/resources/views/backend/taxonomy/terms/delete.blade.php @@ -13,6 +13,20 @@

Are you sure you want to delete "{{ $term->name }}" ?

+ + @if ($term->children()->count() > 0) +

The following terms are linked to this Taxonomy Term, and will be deleted with this.

+ + @endif +
{!! Form::open([ 'url' => route('dashboard.taxonomy.terms.destroy', ['taxonomy' => $taxonomy, 'term' => $term]),