Passed
Push — master ( 0378d7...bd60cc )
by
04:19
created

FaqCategoryController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 7 1
A index() 0 5 1
A edit() 0 5 1
A create() 0 3 1
A store() 0 6 1
A destroy() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the Qsnh/meedu.
5
 *
6
 * (c) XiaoTeng <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace App\Http\Controllers\Backend;
13
14
use App\Models\FaqCategory;
15
use App\Http\Controllers\Controller;
16
use App\Http\Requests\Backend\FaqCategoryRequest;
17
18
class FaqCategoryController extends Controller
19
{
20
    public function index()
21
    {
22
        $categories = FaqCategory::sortAsc()->get();
23
24
        return view('backend.faq_category.index', compact('categories'));
25
    }
26
27
    public function create()
28
    {
29
        return view('backend.faq_category.create');
30
    }
31
32
    public function store(FaqCategoryRequest $request)
33
    {
34
        FaqCategory::create($request->filldata());
35
        flash('添加成功', 'success');
36
37
        return back();
38
    }
39
40
    public function edit($id)
41
    {
42
        $category = FaqCategory::findOrFail($id);
43
44
        return view('backend.faq_category.edit', compact('category'));
45
    }
46
47
    public function update(FaqCategoryRequest $request, $id)
48
    {
49
        $category = FaqCategory::findOrFail($id);
50
        $category->fill($request->filldata())->save();
51
        flash('编辑成功', 'success');
52
53
        return back();
54
    }
55
56
    public function destroy($id)
57
    {
58
        $category = FaqCategory::findOrFail($id);
59
        if ($category->articles()->exists()) {
60
            flash('该分类下存在文章,无法删除');
61
        } else {
62
            $category->delete();
63
            flash('删除成功', 'success');
64
        }
65
66
        return back();
67
    }
68
}
69