update deploy
This commit is contained in:
24
app/Models/Concerns/HasTurkishSlug.php
Normal file
24
app/Models/Concerns/HasTurkishSlug.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait HasTurkishSlug
|
||||
{
|
||||
protected function slugSourceField(): string
|
||||
{
|
||||
return 'title';
|
||||
}
|
||||
|
||||
protected static function bootHasTurkishSlug(): void
|
||||
{
|
||||
static::saving(function ($model): void {
|
||||
if (empty($model->slug) && $model->{$model->slugSourceField()}) {
|
||||
$model->slug = Str::turkishSlug($model->{$model->slugSourceField()});
|
||||
} else {
|
||||
$model->slug = Str::turkishSlug($model->slug);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user