PHP code example of esign / laravel-underscore-sluggable
1. Go to this page and download the library: Download esign/laravel-underscore-sluggable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
esign / laravel-underscore-sluggable example snippets
namespace App\Models;
use Esign\UnderscoreSluggable\HasTranslatableSlug;
use Esign\UnderscoreTranslatable\UnderscoreTranslatable;
use Illuminate\Database\Eloquent\Model;
use Spatie\Sluggable\SlugOptions;
class Post extends Model
{
use UnderscoreTranslatable;
use HasTranslatableSlug;
public $translatable = [
'title',
'slug',
];
public function getSlugOptions(): SlugOptions
{
return SlugOptions::createWithLocales(['en', 'nl'])
->generateSlugsFrom('title')
->saveSlugsTo('slug');
}
}
namespace App\Models;
use Esign\UnderscoreSluggable\HasTranslatableSlug;
use Esign\UnderscoreTranslatable\UnderscoreTranslatable;
use Illuminate\Database\Eloquent\Model;
use Spatie\Sluggable\SlugOptions;
class Post extends Model
{
use UnderscoreTranslatable;
use HasTranslatableSlug;
public $translatable = [
'title',
'slug',
];
public function getSlugOptions(): SlugOptions
{
return SlugOptions::createWithLocales(['en', 'nl'])
->generateSlugsFrom(function (Model $model, string $locale) {
return $model->getTranslation('title', $locale) . '-' . $model->id;
})
->saveSlugsTo('slug');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.