ContentGroupController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 4 1
A index() 0 20 2
A edit() 0 3 1
A destroy() 0 7 2
A update() 0 4 1
A create() 0 3 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * ContentGroupController
5
 *
6
 * This is the controller of the content groups 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\Content\ContentFacade as ContentService;
17
18
class ContentGroupController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = ContentService::getGroupModel()
25
            ->select(['id', 'title'])
26
            ->where('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...
27
28
            $datatables = DataTables::of($query)
29
            ->addColumn('action', function ($query) {
30
                $deleteLink = Form::deleteajax(url()->route('content-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
31
                $links = '<a href="'.url()->route('content-group.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
32
            
33
                return $links;
34
            });
35
36
            return $datatables->make(true);
37
        }
38
        
39
        return view('backend.content_group.index')->with('contentGroup', ContentService::selectAll());
40
    }
41
42
    public function create()
43
    {
44
        return view('backend.content_group.create')->with(array());
45
    }
46
47
    public function store(Request $request)
48
    {
49
        $result  = ContentService::createGroup($request->all());
50
        return ContentService::notificationRedirect('content-group.index', $result, 'The content group was inserted.');
51
    }
52
53
    public function edit($contentGroupId)
54
    {
55
        return view('backend.content_group.edit')->with(array('contentGroup' => ContentService::findGroup($contentGroupId)));
56
    }
57
58
    public function update(Request $request, $contentGroupId)
59
    {
60
        $result  = ContentService::updateGroupById($request->all(), $contentGroupId);
61
        return ContentService::notificationRedirect('content-group.index', $result, 'The content group was updated.');
62
    }
63
64
    /**
65
     * Remove the specified resource from storage
66
     * @param  int  $contentGroupId
67
     * @return Redirect
68
     */
69
    public function destroy($contentGroupId)
70
    {
71
        $result  = ContentService::destroyGroup($contentGroupId);
72
73
        if ($result) {
74
            flash('The content was deleted.');
75
            return redirect()->route('content-group.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route('content-group.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Backend\Redirect.
Loading history...
76
        }
77
    }
78
}
79