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

CouponGroupController::__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
 * CouponGroupController
5
 *
6
 * This is the controller of the coupons 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 Form;
15
16
use Hideyo\Ecommerce\Framework\Services\Coupon\CouponFacade as CouponService;
17
18
class CouponGroupController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = CouponService::getGroupModel()->select(['id', 'title'])
25
            ->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...
26
27
            $datatables = \Datatables::of($query)
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...
28
            ->addColumn('action', function ($query) {
29
                $deleteLink = Form::deleteajax(url()->route('coupon-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-sm btn-danger'));
30
                $links = '<a href="'.url()->route('coupon-group.edit', $query->id).'" class="btn btn-sm btn-success"><i class="fi-pencil"></i>Edit</a>  '.$deleteLink;
31
                return $links;
32
            });
33
34
            return $datatables->make(true);
35
        }
36
        
37
        return view('backend.coupon-group.index')->with('couponGroup', CouponService::selectAll());
38
    }
39
40
    public function create()
41
    {
42
        return view('backend.coupon-group.create')->with(array());
43
    }
44
45
    public function store(Request $request)
46
    {
47
        $result  = CouponService::createGroup($request->all());
48
        return CouponService::notificationRedirect('coupon-group.index', $result, 'The coupon group was inserted.');
49
    }
50
51
    public function edit($couponGroupId)
52
    {
53
        return view('backend.coupon-group.edit')->with(array('couponGroup' => CouponService::findGroup($couponGroupId)));
54
    }
55
56
    public function update(Request $request, $couponGroupId)
57
    {
58
        $result  = CouponService::updateGroupById($request->all(), $couponGroupId);
59
        return CouponService::notificationRedirect('coupon-group.index', $result, 'The coupon group was updated.');
60
    }
61
62
    public function destroy($couponGroupId)
63
    {
64
        $result  = CouponService::destroyGroup($couponGroupId);
65
66
        if ($result) {
67
            Notification::success('The coupon was deleted.');
68
            return redirect()->route('coupon-group.index');
69
        }
70
    }
71
}
72