PHP code example of amdadulhaq / unique-slug-laravel
1. Go to this page and download the library: Download amdadulhaq/unique-slug-laravel 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/ */
amdadulhaq / unique-slug-laravel example snippets
namespace App\Models;
use AmdadulHaq\UniqueSlug\HasSlug;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
use HasSlug;
protected $fillable = ['name', 'slug'];
}
class Article extends Model
{
use HasSlug;
public function getSlugSourceAttribute(): string
{
return 'title'; // Generate slug from title field
}
public function getSlugNameAttribute(): string
{
return 'slug'; // Store slug in slug field
}
public function getSlugSeparator(): string
{
return '_'; // Use underscore separator
}
}
class Article extends Model
{
use HasSlug;
use \Illuminate\Database\Eloquent\SoftDeletes;
}
// Include soft deleted records in uniqueness check
config(['slug.