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

ContentGroupController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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 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\Content\ContentFacade as ContentService;
18
19
class ContentGroupController extends Controller
20
{
21
    public function index(Request $request)
22
    {
23
        if ($request->wantsJson()) {
24
25
            $query = ContentService::getGroupModel()
26
            ->select(['id', 'title'])
27
            ->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...
28
29
            $datatables = Datatables::of($query)
30
            ->addColumn('action', function ($query) {
31
                $deleteLink = Form::deleteajax(url()->route('content-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
32
                $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;
33
            
34
                return $links;
35
            });
36
37
            return $datatables->make(true);
38
        }
39
        
40
        return view('backend.content_group.index')->with('contentGroup', ContentService::selectAll());
41
    }
42
43
    public function create()
44
    {
45
        return view('backend.content_group.create')->with(array());
46
    }
47
48
    public function store(Request $request)
49
    {
50
        $result  = ContentService::createGroup($request->all());
51
        return ContentService::notificationRedirect('content-group.index', $result, 'The content group was inserted.');
52
    }
53
54
    public function edit($contentGroupId)
55
    {
56
        return view('backend.content_group.edit')->with(array('contentGroup' => ContentService::findGroup($contentGroupId)));
57
    }
58
59
    public function update(Request $request, $contentGroupId)
60
    {
61
        $result  = ContentService::updateGroupById($request->all(), $contentGroupId);
62
        return ContentService::notificationRedirect('content-group.index', $result, 'The content group was updated.');
63
    }
64
65
    /**
66
     * Remove the specified resource from storage
67
     * @param  int  $contentGroupId
68
     * @return Redirect
69
     */
70
    public function destroy($contentGroupId)
71
    {
72
        $result  = ContentService::destroyGroup($contentGroupId);
73
74
        if ($result) {
75
            Notification::success('The content was deleted.');
76
            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...
77
        }
78
    }
79
}
80