Passed
Push — master ( 65a680...2232db )
by Matthijs
17:59 queued 12:07
created

FaqItemController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 Notification;
14
use Datatables;
0 ignored issues
show
Bug introduced by
The type Datatables was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Form;
16
17
use Hideyo\Ecommerce\Framework\Services\Faq\FaqFacade as FaqService;
18
19
class FaqItemController extends Controller
20
{
21
    public function index(Request $request)
22
    {
23
        if ($request->wantsJson()) {
24
25
            $query = FaqService::getModel()->select(
26
                [
27
                
28
                'faq_item.id', 
29
                'faq_item.faq_item_group_id',
30
                'faq_item.question', 
31
                'faq_item.answer', 
32
                'faq_item_group.title as grouptitle']
33
            )
34
            ->with(array('faqItemGroup'))
35
            ->leftJoin('faq_item_group', 'faq_item_group.id', '=', 'faq_item.faq_item_group_id')
36
            ->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...
37
38
            $datatables = Datatables::of($query)
39
            ->addColumn('faqitemgroup', function ($query) {
40
                return $query->grouptitle;
41
            })
42
            ->addColumn('action', function ($query) {
43
                $deleteLink = Form::deleteajax(url()->route('faq.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
44
                $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;
45
            
46
                return $links;
47
            });
48
49
            return $datatables->make(true);
50
51
        }
52
        
53
        return view('backend.faq-item.index')->with('faq', FaqService::selectAll());
54
    }
55
56
    public function create()
57
    {
58
        $groups = FaqService::selectAllGroups()->pluck('title', 'id')->toArray();
59
        return view('backend.faq-item.create')->with(array('groups' => $groups));
60
    }
61
62
    public function store(Request $request)
63
    {
64
        $result  = FaqService::create($request->all());
65
        return FaqService::notificationRedirect('faq.index', $result, 'FaqItem was inserted.');
66
    }
67
68
    public function edit($faqItemId)
69
    {
70
        $groups = FaqService::selectAllGroups()->pluck('title', 'id')->toArray();
71
        return view('backend.faq-item.edit')->with(array('faq' => FaqService::find($faqItemId), 'groups' => $groups));
72
    }
73
74
    public function update(Request $request, $faqId)
75
    {
76
        $result  = FaqService::updateById($request->all(), $faqId);
77
        return FaqService::notificationRedirect('faq.index', $result, 'FaqItem was updated.');
78
    }
79
80
    public function destroy($faqItemId)
81
    {
82
        $result  = FaqService::destroy($faqItemId);
83
84
        if ($result) {
85
            Notification::success('The faq was deleted.');
86
            return redirect()->route('faq.index');
87
        }
88
    }
89
}
90