/** * Whenever a user is created, create a new slug based on their username. */ public static function boot() { parent::boot(); static::creating(function ($user) { $user->slug = Slug::fromTitle($user->username); }); }
public static function boot() { parent::boot(); static::created(function ($comment) { $comment->slug = Slug::fromId($comment->id); }); }
public function handle(ModifyDiscussionCommand $command) { $discussion = $this->discussions->getBySlug($command->discussionSlug); $discussion->title = $command->title; $discussion->slug = Slug::fromTitle($command->title); $this->discussions->save($discussion); }
/** * Handle the command, retrieving the category and returning the result of the update operation * * @param UpdateCategoryCommand $command * @return Resource */ public function handle(ModifyCategoryCommand $command) { $category = $this->categories->getById($command->id); if (!empty($command->attributes['title'])) { $category->title = $command->attributes['title']; $category->slug = Slug::fromTitle($command->attributes['title']); } $category->description = $command->attributes['description'] ?: $category->description; return $this->categories->update($category, $command->attributes); }
/** * @param ModifyCategoryRequest $request * @return \Illuminate\Http\RedirectResponse */ public function update(ModifyCategoryRequest $request) { $this->dispatch(new ModifyCategoryCommand($request->get('id'), $request->only(['title', 'description']))); return redirect()->route('category.show', [Slug::fromTitle($request->get('title'))]); }