Code Duplication    Length = 124-127 lines in 2 locations

app/Http/Controllers/Admin/Blog/CategoryController.php 1 location

@@ 12-135 (lines=124) @@
9
use Xetaravel\Models\Repositories\CategoryRepository;
10
use Xetaravel\Models\Validators\CategoryValidator;
11
12
class CategoryController extends Controller
13
{
14
    /**
15
     * Constructor.
16
     */
17
    public function __construct()
18
    {
19
        parent::__construct();
20
21
        $this->breadcrumbs->addCrumb('Blog', route('admin.blog.article.index'));
22
    }
23
24
    /**
25
     * Show all categories.
26
     *
27
     * @return \Illuminate\View\View
28
     */
29
    public function index(): View
30
    {
31
        $categories = Category::paginate(config('xetaravel.pagination.blog.article_per_page'));
32
33
        $this->breadcrumbs->addCrumb('Manage Categories', route('admin.blog.category.index'));
34
35
        return view('Admin::Blog.category.index', ['categories' => $categories, 'breadcrumbs' => $this->breadcrumbs]);
36
    }
37
38
    /**
39
     * Show the caterory create form.
40
     *
41
     * @return \Illuminate\View\View
42
     */
43
    public function showCreateForm(): View
44
    {
45
        $breadcrumbs = $this->breadcrumbs
46
            ->addCrumb('Manage Categories', route('admin.blog.category.index'))
47
            ->addCrumb("Create", route('admin.blog.category.create'));
48
49
        return view('Admin::Blog.category.create', ['breadcrumbs' => $this->breadcrumbs]);
50
    }
51
52
    /**
53
     * Handle a category create request for the application.
54
     *
55
     * @param \Illuminate\Http\Request $request
56
     *
57
     * @return \Illuminate\Http\RedirectResponse
58
     */
59
    public function create(Request $request): RedirectResponse
60
    {
61
        CategoryValidator::create($request->all())->validate();
62
        CategoryRepository::create($request->all());
63
64
        return redirect()
65
            ->route('admin.blog.category.index')
66
            ->with('success', 'Your category has been created successfully !');
67
    }
68
69
    /**
70
     * Show the category update form.
71
     *
72
     * @param string $slug The slug of the category.
73
     * @param int $id The id of the category.
74
     *
75
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
76
     */
77
    public function showUpdateForm(string $slug, int $id)
78
    {
79
        $category = Category::findOrFail($id);
80
81
        $breadcrumbs = $this->breadcrumbs
82
            ->addCrumb('Manage Categories', route('admin.blog.category.index'))
83
            ->addCrumb(
84
                "Update : " . e(str_limit($category->title, 30)),
85
                route(
86
                    'admin.blog.category.index',
87
                    ['slug' => $category->slug, 'id' => $category->id]
88
                )
89
            );
90
91
        return view('Admin::Blog.category.update', compact('category', 'breadcrumbs'));
92
    }
93
94
    /**
95
     * Handle an category update request for the application.
96
     *
97
     * @param \Illuminate\Http\Request $request
98
     * @param int $id The id of the category.
99
     *
100
     * @return \Illuminate\Http\RedirectResponse
101
     */
102
    public function update(Request $request, int $id): RedirectResponse
103
    {
104
        $category = Category::findOrFail($id);
105
106
        CategoryValidator::update($request->all(), $id)->validate();
107
        CategoryRepository::update($request->all(), $category);
108
109
        return redirect()
110
            ->route('admin.blog.category.index')
111
            ->with('success', 'Your category has been updated successfully !');
112
    }
113
114
    /**
115
     * Handle the delete request for the category.
116
     *
117
     * @param int $id The id of the category to delete.
118
     *
119
     * @return \Illuminate\Http\RedirectResponse
120
     */
121
    public function delete(int $id): RedirectResponse
122
    {
123
        $category = Category::findOrFail($id);
124
125
        if ($category->delete()) {
126
            return redirect()
127
                ->route('admin.blog.category.index')
128
                ->with('success', 'This category has been deleted successfully !');
129
        }
130
131
        return redirect()
132
            ->route('admin.blog.category.index')
133
            ->with('danger', 'An error occurred while deleting this category !');
134
    }
135
}
136

app/Http/Controllers/Admin/Discuss/CategoryController.php 1 location

@@ 12-138 (lines=127) @@
9
use Xetaravel\Models\Repositories\DiscussCategoryRepository;
10
use Xetaravel\Models\Validators\DiscussCategoryValidator;
11
12
class CategoryController extends Controller
13
{
14
    /**
15
     * Constructor.
16
     */
17
    public function __construct()
18
    {
19
        parent::__construct();
20
21
        $this->breadcrumbs->addCrumb('Discuss', route('admin.discuss.category.index'));
22
    }
23
24
    /**
25
     * Show all categories.
26
     *
27
     * @return \Illuminate\View\View
28
     */
29
    public function index(): View
30
    {
31
        $categories = DiscussCategory::paginate(config('xetaravel.pagination.discuss.conversation_per_page'));
32
33
        $this->breadcrumbs->addCrumb('Manage Categories', route('admin.discuss.category.index'));
34
35
        return view(
36
            'Admin::Discuss.category.index',
37
            ['categories' => $categories, 'breadcrumbs' => $this->breadcrumbs]
38
        );
39
    }
40
41
    /**
42
     * Show the caterory create form.
43
     *
44
     * @return \Illuminate\View\View
45
     */
46
    public function showCreateForm(): View
47
    {
48
        $breadcrumbs = $this->breadcrumbs
49
            ->addCrumb('Manage Categories', route('admin.discuss.category.index'))
50
            ->addCrumb("Create", route('admin.discuss.category.create'));
51
52
        return view('Admin::Discuss.category.create', ['breadcrumbs' => $this->breadcrumbs]);
53
    }
54
55
    /**
56
     * Handle a category create request for the application.
57
     *
58
     * @param \Illuminate\Http\Request $request
59
     *
60
     * @return \Illuminate\Http\RedirectResponse
61
     */
62
    public function create(Request $request): RedirectResponse
63
    {
64
        DiscussCategoryValidator::create($request->all())->validate();
65
        DiscussCategoryRepository::create($request->all());
66
67
        return redirect()
68
            ->route('admin.discuss.category.index')
69
            ->with('success', 'Your category has been created successfully !');
70
    }
71
72
    /**
73
     * Show the category update form.
74
     *
75
     * @param string $slug The slug of the category.
76
     * @param int $id The id of the category.
77
     *
78
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
79
     */
80
    public function showUpdateForm(string $slug, int $id)
81
    {
82
        $category = DiscussCategory::findOrFail($id);
83
84
        $breadcrumbs = $this->breadcrumbs
85
            ->addCrumb('Manage Categories', route('admin.discuss.category.index'))
86
            ->addCrumb(
87
                "Update : " . e(str_limit($category->title, 30)),
88
                route(
89
                    'admin.discuss.category.index',
90
                    ['slug' => $category->slug, 'id' => $category->id]
91
                )
92
            );
93
94
        return view('Admin::Discuss.category.update', compact('category', 'breadcrumbs'));
95
    }
96
97
    /**
98
     * Handle an category update request for the application.
99
     *
100
     * @param \Illuminate\Http\Request $request
101
     * @param int $id The id of the category.
102
     *
103
     * @return \Illuminate\Http\RedirectResponse
104
     */
105
    public function update(Request $request, int $id): RedirectResponse
106
    {
107
        $category = DiscussCategory::findOrFail($id);
108
109
        DiscussCategoryValidator::update($request->all(), $id)->validate();
110
        DiscussCategoryRepository::update($request->all(), $category);
111
112
        return redirect()
113
            ->route('admin.discuss.category.index')
114
            ->with('success', 'Your category has been updated successfully !');
115
    }
116
117
    /**
118
     * Handle the delete request for the category.
119
     *
120
     * @param int $id The id of the category to delete.
121
     *
122
     * @return \Illuminate\Http\RedirectResponse
123
     */
124
    public function delete(int $id): RedirectResponse
125
    {
126
        $category = DiscussCategory::findOrFail($id);
127
128
        if ($category->delete()) {
129
            return redirect()
130
                ->route('admin.discuss.category.index')
131
                ->with('success', 'This category has been deleted successfully !');
132
        }
133
134
        return redirect()
135
            ->route('admin.discuss.category.index')
136
            ->with('danger', 'An error occurred while deleting this category !');
137
    }
138
}
139