PHP code example of bpocallaghan / sluggable
1. Go to this page and download the library: Download bpocallaghan/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/ */
bpocallaghan / sluggable example snippets
$model = new EloquentModel();
$model->name = 'laravel is awesome';
$model->save();
echo $model->slug; // ouputs "laravel-is-awesome"
class YourEloquentModel extends Model
{
use HasSlug;
/**
* This function is optional and only return SlugOptions::create()
->slugSeperator('-')
->generateSlugFrom('name')
->saveSlugTo('slug');
}
}
class YourEloquentModel extends Model
{
use HasSlug;
public function getNameAndFooAttribute()
{
$name = $this->name;
if ($this->foo) {
$name .= " {$this->foo->name}";
}
return $name;
}
protected function getSlugOptions()
{
return SlugOptions::create()
->generateSlugFrom('name_and_foo');
}
}