Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/public_html/test.tradze.com/vendor/cviebrock/eloquent-sluggable/src/ |
<?php namespace Cviebrock\EloquentSluggable;
use Cviebrock\EloquentSluggable\Services\SlugService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
/**
* Class Sluggable
*
* @package Cviebrock\EloquentSluggable
*/
trait Sluggable
{
/**
* Hook into the Eloquent model events to create or
* update the slug as required.
*/
public static function bootSluggable()
{
static::observe(app(SluggableObserver::class));
}
/**
* Register a slugging model event with the dispatcher.
*
* @param \Closure|string $callback
* @return void
*/
public static function slugging($callback)
{
static::registerModelEvent('slugging', $callback);
}
/**
* Register a slugged model event with the dispatcher.
*
* @param \Closure|string $callback
* @return void
*/
public static function slugged($callback)
{
static::registerModelEvent('slugged', $callback);
}
/**
* Clone the model into a new, non-existing instance.
*
* @param array|null $except
* @return Model
*/
public function replicate(array $except = null)
{
$instance = parent::replicate($except);
(new SlugService())->slug($instance, true);
return $instance;
}
/**
* Query scope for finding "similar" slugs, used to determine uniqueness.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $attribute
* @param array $config
* @param string $slug
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeFindSimilarSlugs(Builder $query, Model $model, $attribute, $config, $slug)
{
$separator = $config['separator'];
return $query->where(function(Builder $q) use ($attribute, $slug, $separator) {
$q->where($attribute, '=', $slug)
->orWhere($attribute, 'LIKE', $slug . $separator . '%');
});
}
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
abstract public function sluggable();
}