This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Alexandre
Alexandre

i want to save slugged attribute on database utilizing Attribute Modifiers.

my model

// [...]

use Model;
use October\Rain\Database\Traits\Sluggable;

class Program extends \October\Rain\Database\Model
{
    protected $slugs = ['slug' => 'title'];

// [...]

i have slug and title column on Program database table but when i save some model the slug column always is NULL. This is right?

how the right way to save it?

Last updated

dazmiller8556
dazmiller8556

Have you added it to your $fillable array?

Just a guess,

Alexandre
Alexandre

no, is this necessary?

Alexandre
Alexandre

now i have added to $fillable slug and title

protected $fillable = ['slug', 'title'];

and the slug column continues to receive null

Alexandre
Alexandre

well, i could not make it work so above my workaround

$model = new Program;
$model->title = 'title of program';
$model->slug = str_slug( $model->title );
$model->save();

i'm using laravel helper function str_slug( string $value, string $separator = '-' )

Last updated

Alexandre
Alexandre

ok, consider that the best way for now

inside my program database table string('slug', 255)

and inside my Program model class

class Program extends Model 
{
    protected $connection = 'my_connection';
    protected $table = 'my_program_table';

    public function beforeCreate()
    {
        $this->slug = \Str::slug( $this->title );
    }

    // [...]
}

Last updated

1-6 of 6

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.