I am trying to learn laravel 5 using this wondefull site . For my activity model, I want to generate bullets before storing it in my database, so I created the following model.
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Activity extends Model { protected $table = 'activitys'; protected $fillable = [ 'title', 'text', 'subtitle' ];
But when I save the object using the Activity model, the slug does not fill up, I tried changing it to $ this-> attributes ['title'] = "test" for testing, but it did not start. I also tried adding the parameters $ title, $ slug to setSlugAttribute (), but it did not help.
What am I doing wrong and can someone explain the parameter used in some examples for setSomeAttribute ($ whyParameterHere).
Note: there is an empty field in my database.
As suggested by user 3158900, I tried:
public function setTitleAttribute($title){ $this->title = $title; $this->attributes['slug'] = str_slug($this->title , "-"); }
This makes my header field empty, but keeps the pool the way I want it, why is this $ this-> title empty then? If I remove $ this-> title = $ title; both the header and the pool are empty
php laravel laravel-5
Sven van den boogaart
source share