FaqItemController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 32
c 1
b 0
f 1
dl 0
loc 65
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 4 1
A edit() 0 4 1
A destroy() 0 7 2
A index() 0 30 2
A update() 0 4 1
A create() 0 4 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * FaqItemController
5
 *
6
 * This is the controller of the faqs of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
use Illuminate\Http\Request;
13
use DataTables;
14
use Form;
15
16
use Hideyo\Ecommerce\Framework\Services\Faq\FaqFacade as FaqService;
17
18
class FaqItemController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = FaqService::getModel()->select(
25
                ['faq_item.id', 
26
                'faq_item.faq_item_group_id',
27
                'faq_item.question', 
28
                'faq_item.answer', 
29
                'faq_item_group.title as grouptitle']
30
            )
31
            ->with(array('faqItemGroup'))
32
            ->leftJoin('faq_item_group', 'faq_item_group.id', '=', 'faq_item.faq_item_group_id')
33
            ->where('faq_item.shop_id', '=', auth('hideyobackend')->user()->selected_shop_id);
0 ignored issues
show
Bug introduced by
Accessing selected_shop_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
34
35
            $datatables = DataTables::of($query)
36
            ->addColumn('faqitemgroup', function ($query) {
37
                return $query->grouptitle;
38
            })
39
            ->addColumn('action', function ($query) {
40
                $deleteLink = Form::deleteajax(url()->route('faq.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
41
                $links = '<a href="'.url()->route('faq.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
42
            
43
                return $links;
44
            });
45
46
            return $datatables->make(true);
47
        }
48
        
49
        return view('backend.faq-item.index')->with('faq', FaqService::selectAll());
50
    }
51
52
    public function create()
53
    {
54
        $groups = FaqService::selectAllGroups()->pluck('title', 'id')->toArray();
55
        return view('backend.faq-item.create')->with(array('groups' => $groups));
56
    }
57
58
    public function store(Request $request)
59
    {
60
        $result  = FaqService::create($request->all());
61
        return FaqService::notificationRedirect('faq.index', $result, 'FaqItem was inserted.');
62
    }
63
64
    public function edit($faqItemId)
65
    {
66
        $groups = FaqService::selectAllGroups()->pluck('title', 'id')->toArray();
67
        return view('backend.faq-item.edit')->with(array('faq' => FaqService::find($faqItemId), 'groups' => $groups));
68
    }
69
70
    public function update(Request $request, $faqId)
71
    {
72
        $result  = FaqService::updateById($request->all(), $faqId);
73
        return FaqService::notificationRedirect('faq.index', $result, 'FaqItem was updated.');
74
    }
75
76
    public function destroy($faqItemId)
77
    {
78
        $result  = FaqService::destroy($faqItemId);
79
80
        if ($result) {
81
            flash('The faq was deleted.');
82
            return redirect()->route('faq.index');
83
        }
84
    }
85
}
86