slug($value)->firstOrFail(); } /** * Set the character's name. * * @param string $value * @return void */ public function setNameAttribute($value) { $this->attributes['name'] = Str::ucfirst(Str::lower($value)); } /** * Retrieve the user that owns this character. */ public function user() { return $this->belongsTo(User::class); } /** * Check if this character is the user's main character */ public function isMain() { return $this->user->character_id == $this->id; } /** * Retrieve the character's professions. */ public function professions() { return $this->hasMany(CharacterProfession::class); } public function scopeSlug($q, $name) { return $q->where('name', Str::ucfirst(Str::lower($name))); } public function getSlugAttribute() { return Str::lower($this->name); } }