Add all files

This commit is contained in:
root
2025-11-30 11:57:22 +01:00
parent 2ee51cac4f
commit 044271db3d
1476 changed files with 142544 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Observers;
use App\Models\Category;
class CategoryObserver
{
/**
* Handle the Category "creating" event.
*
* @return void
*/
public function creating(Category $category)
{
$parent = $category->parent;
$full_slug = $category->slug;
// Set full_slug
while ($parent) {
$fullSlug = $parent->slug;
$full_slug = $fullSlug . '/' . $full_slug;
$parent = $parent->parent;
}
$category->full_slug = $full_slug;
}
/**
* Handle the Category "updating" event.
*
* @return void
*/
public function updating(Category $category)
{
// Did parent or slug change?
if ($category->isDirty('parent_id') || $category->isDirty('slug')) {
$parent = $category->parent;
$full_slug = $category->slug;
// Set full_slug
while ($parent) {
$fullSlug = $parent->slug;
$full_slug = $fullSlug . '/' . $full_slug;
$parent = $parent->parent;
}
$category->full_slug = $full_slug;
// Update children
$category->children->each(function ($child) use ($category) {
$child->update([
'full_slug' => $category->full_slug . '/' . $child->slug,
]);
});
}
}
}