ShopController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 23
c 3
b 0
f 1
dl 0
loc 57
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A destroy() 0 7 2
A update() 0 4 1
A store() 0 4 1
A index() 0 24 3
A edit() 0 3 1
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * ShopController
5
 *
6
 * This is the controller of the shops
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
use Hideyo\Ecommerce\Framework\Services\Shop\ShopFacade as ShopService;
16
17
class ShopController extends Controller
18
{
19
    public function index(Request $request)
20
    {
21
        if ($request->wantsJson()) {
22
23
            $query = ShopService::getModel()->select(['id', 'title', 'url', 'logo_file_name']);
24
25
            $datatables = DataTables::of($query)
26
27
            ->addColumn('action', function ($query) {
28
                $deleteLink = Form::deleteajax(url()->route('shop.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
29
                $links = '<a href="'.url()->route('shop.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
30
                return $links;
31
            })
32
33
            ->addColumn('image', function ($query) {
34
                if ($query->logo_file_name) {
35
                    return '<img src="/files/shop/'.$query->id.'/'.$query->logo_file_name.'"  />';
36
                }
37
            });
38
39
            return $datatables->rawColumns(['image', 'action'])->make(true);
40
        }
41
        
42
        return view('backend.shop.index')->with('shop', ShopService::selectAll());
43
    }
44
45
    public function create()
46
    {
47
        return view('backend.shop.create');
48
    }
49
50
    public function store(Request $request)
51
    {
52
        $result = ShopService::create($request->all());
53
        return ShopService::notificationRedirect('shop.index', $result, 'The shop was inserted.');
54
    }
55
56
    public function edit($shopId)
57
    {
58
        return view('backend.shop.edit')->with(array('shop' => ShopService::find($shopId)));
59
    }
60
61
    public function update(Request $request, $shopId)
62
    {
63
        $result = ShopService::updateById($request->all(), $shopId);
64
        return ShopService::notificationRedirect('shop.index', $result, 'The shop was updated.');
65
    }
66
67
    public function destroy($shopId)
68
    {
69
        $result = ShopService::destroy($shopId);
70
        
71
        if ($result) {
72
            flash('The shop was deleted.');
73
            return redirect()->route('shop.index');
74
        }
75
    }
76
}