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

FaqArticleController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\FaqArticle;
15
use App\Models\FaqCategory;
16
use App\Http\Controllers\Controller;
17
use App\Http\Requests\Backend\FaqArticleRequest;
18
19
class FaqArticleController extends Controller
20
{
21
    public function index()
22
    {
23
        $articles = FaqArticle::with('category')->orderByDesc('updated_at')->paginate(15);
24
25
        return view('backend.faq_article.index', compact('articles'));
26
    }
27
28
    public function create()
29
    {
30
        $categories = FaqCategory::all();
31
32
        return view('backend.faq_article.create', compact('categories'));
33
    }
34
35
    public function store(FaqArticleRequest $request)
36
    {
37
        FaqArticle::create($request->filldata());
38
        flash('添加成功', 'success');
39
40
        return back();
41
    }
42
43
    public function edit($id)
44
    {
45
        $article = FaqArticle::findOrFail($id);
46
        $categories = FaqCategory::all();
47
48
        return view('backend.faq_article.edit', compact('article', 'categories'));
49
    }
50
51
    public function update(FaqArticleRequest $request, $id)
52
    {
53
        $article = FaqArticle::findOrFail($id);
54
        $article->fill($request->filldata())->save();
55
        flash('编辑成功', 'success');
56
57
        return back();
58
    }
59
60
    public function destroy($id)
61
    {
62
        $article = FaqArticle::findOrFail($id);
63
        $article->delete();
64
        flash('删除成功', 'success');
65
66
        return back();
67
    }
68
}
69