Passed
Push — master ( f4b030...a2b3af )
by Matthijs
22:06 queued 15:53
created

ShopController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 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
use Hideyo\Ecommerce\Framework\Services\Shop\ShopFacade as ShopService;
17
18
class ShopController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
24
            $query = ShopService::getModel()
25
            ->select(['id', 'title', 'logo_file_name']);
26
            $datatables = Datatables::of($query)
27
28
            ->addColumn('action', function ($query) {
29
                $deleteLink = Form::deleteajax(url()->route('shop.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
30
                $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;
31
                return $links;
32
            })
33
34
            ->addColumn('image', function ($query) {
35
                if ($query->logo_file_name) {
36
                    return '<img src="http://shop.brulo.nl/files/'.$query->id.'/logo/'.$query->logo_file_name.'"  />';
37
                }
38
            });
39
40
            return $datatables->make(true);
41
        }
42
        
43
        return view('backend.shop.index')->with('shop', ShopService::selectAll());
44
    }
45
46
    public function create()
47
    {
48
        return view('backend.shop.create');
49
    }
50
51
    public function store(Request $request)
52
    {
53
        $result  = ShopService::create($request->all());
54
        return ShopService::notificationRedirect('shop.index', $result, 'The shop was inserted.');
55
    }
56
57
    public function edit($shopId)
58
    {
59
        return view('backend.shop.edit')->with(array('shop' => ShopService::find($shopId)));
60
    }
61
62
    public function update(Request $request, $shopId)
63
    {
64
        $result  = ShopService::updateById($request->all(), $shopId);
65
        return ShopService::notificationRedirect('shop.index', $result, 'The shop was updated.');
66
    }
67
68
    public function destroy($shopId)
69
    {
70
        $result  = ShopService::destroy($shopId);
71
72
        if ($result) {
73
            Notification::success('The shop was deleted.');
74
            return redirect()->route('shop.index');
75
        }
76
    }
77
}