CouponGroupController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

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

6 Methods

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