Skip to content

Commit

Permalink
chore: published livewire assets and added slug mutation trait to the…
Browse files Browse the repository at this point in the history
… collection model
  • Loading branch information
CS76 committed Jan 15, 2025
1 parent c3ede0f commit cc0be42
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
namespace App\Filament\Dashboard\Resources\CollectionResource\Pages;

use App\Filament\Dashboard\Resources\CollectionResource;
use App\Models\Collection;
use Filament\Resources\Pages\CreateRecord;

class CreateCollection extends CreateRecord
{
protected static string $resource = CollectionResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
return Collection::mutateFormData($data);
}
}
15 changes: 15 additions & 0 deletions app/Filament/Traits/MutatesCollectionFormData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Filament\Traits;

use Str;

trait MutatesCollectionFormData
{
protected static function mutateFormData(array $data): array
{
$data['slug'] = Str::slug($data['title']);

return $data;
}
}
2 changes: 2 additions & 0 deletions app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Filament\Traits\MutatesCollectionFormData;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand All @@ -19,6 +20,7 @@ class Collection extends Model implements Auditable, HasMedia
use HasFactory;
use HasTags;
use InteractsWithMedia;
use MutatesCollectionFormData;
use \OwenIt\Auditing\Auditable;

protected static function booted()
Expand Down
Loading

0 comments on commit cc0be42

Please sign in to comment.