public static function boot() { parent::boot(); Category::saving(function ($category) { if (!$category->slug) { $category->slug = str_slug($category->name); } }); }
public function update(CreateCategoryRequest $request, $id) { $category = Category::findOrFail($id); if ($category->user->id !== $this->user->id) { abort(403); } $category->name = $request->get('name'); $category->slug = $request->get('slug'); $category->description = $request->get('description'); $saved = $category->save(); if (!$saved) { return redirect()->back()->with('error', "Category could not be updated."); } return redirect()->route('dashboard')->with('success', "Category has been updated"); }