Ejemplo n.º 1
0
 public static function boot()
 {
     parent::boot();
     Category::saving(function ($category) {
         if (!$category->slug) {
             $category->slug = str_slug($category->name);
         }
     });
 }
Ejemplo n.º 2
0
 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");
 }