diff --git a/app/Http/Controllers/Admin/CategoryController.php b/app/Http/Controllers/Admin/CategoryController.php
index 6eac3df..9b4a6f0 100644
--- a/app/Http/Controllers/Admin/CategoryController.php
+++ b/app/Http/Controllers/Admin/CategoryController.php
@@ -8,6 +8,7 @@
use App\Http\Requests\CreateCategoryRequest;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
+use App\Http\Requests\UpdateCategoryRequest;
class CategoryController extends Controller
{
@@ -21,6 +22,14 @@ public function newCategoryForm(){
}
public function createCategory(CreateCategoryRequest $request){
+ $this->validate($request,
+ [
+ 'slug'=>'unique:categories,slug'
+ ],
+ [
+ 'slug.unique'=>'Slug-ul este deja folosit de o altă categorie!'
+ ]
+ );
$category = new Category();
$category->title = $request->title;
$category->subtitle = $request->subtitle;
@@ -49,7 +58,17 @@ public function editCategoryForm($id){
return view('admin.category.edit-category')->with('category', $category);
}
- public function editCategory(Request $request, $id){
+ public function editCategory(CreateCategoryRequest $request, $id){
+
+ $this->validate($request,
+ [
+ 'slug'=>'unique:categories,slug,'.$id,
+ ],
+ [
+ 'slug.unique'=>'Slug-ul este deja folosit de o altă categorie!'
+ ]
+ );
+
$category = Category::find($id);
if($request->hasFile('photo')){
@@ -72,4 +91,13 @@ public function editCategory(Request $request, $id){
$category->save();
return redirect(route('categories'))->withInput()->with('success', 'Categoria' .' '.$category->title. ' '. 'a fost editată cu succes!');
}
+
+ public function deleteCategory($id){
+ $category = Category::find($id);
+ if(!($category->photo == 'category.jpg')){
+ File::delete('images/categories/'.$category->photo);
+ }
+ $category->delete();
+ return redirect(route('categories'))->withInput()->with('success', 'Categoria' .' '.$category->title. ' '. 'a fost ștearsă cu succes!');
+ }
}
diff --git a/app/Http/Requests/CreateCategoryRequest.php b/app/Http/Requests/CreateCategoryRequest.php
index d4ac250..89ce949 100644
--- a/app/Http/Requests/CreateCategoryRequest.php
+++ b/app/Http/Requests/CreateCategoryRequest.php
@@ -26,7 +26,7 @@ public function rules()
return [
'title' => 'required|max:50',
'subtitle' => 'max:255',
- 'slug' => 'required|max:255|unique:categories',
+ 'slug' => 'required|max:255',
'excerpt' => 'max:6000',
'photo' => 'max:2048',
'meta_title' => 'max:255',
@@ -42,7 +42,6 @@ public function messages(){
'subtitle.max' => 'Subtitlul nu poate avea mai mult de 255 de caractere',
'slug.required' => 'Slug-ul este obligatoriu',
'slug.max' => 'Slug-ul nu poate avea mai mult de 255 de caractere',
- 'slug.unique' => 'Slug-ul trebuie să fie unic',
'excerpt.max' => 'Excerpt-ul nu poate avea mai mult de 6000 de caractere',
'photo.max' => 'Imaginea nu poate avea mai mult de 2MB',
'meta_title.max' => 'Meta titlul nu poate avea mai mult de 255 de caractere',
diff --git a/public/images/categories/CartideFilozofie_1672433196.jpg b/public/images/categories/CartideFilozofie_1672433196.jpg
deleted file mode 100644
index fe7486a..0000000
Binary files a/public/images/categories/CartideFilozofie_1672433196.jpg and /dev/null differ
diff --git a/resources/views/admin/category/categories.blade.php b/resources/views/admin/category/categories.blade.php
index 1c7084a..aafe331 100644
--- a/resources/views/admin/category/categories.blade.php
+++ b/resources/views/admin/category/categories.blade.php
@@ -25,7 +25,6 @@
Titlu
- Subtitlu
Vizualizări
Fotografie
Meta Description & Meta Keywords
@@ -35,11 +34,9 @@
{{$c->subtitle}}