BrandController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 4 1
A edit() 0 3 1
A create() 0 3 1
A destroy() 0 6 2
A index() 0 16 2
A store() 0 4 1
1
<?php namespace App\Http\Controllers\Backend;
2
/**
3
 * BrandController
4
 *
5
 * This is the controller of the brands of the shop
6
 * @author Matthijs Neijenhuijs <[email protected]>
7
 * @version 0.1
8
 */
9
10
use App\Http\Controllers\Controller;
11
use Illuminate\Http\Request;
12
use Form;
13
use DataTables;
14
15
use Hideyo\Ecommerce\Framework\Services\Brand\BrandFacade as BrandService;
16
17
class BrandController extends Controller
18
{
19
    public function index(Request $request)
20
    {
21
        if ($request->wantsJson()) {
22
            $brand = BrandService::getModel()->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...
23
            
24
            $datatables = DataTables::of($brand)->addColumn('action', function ($query) {
25
                $deleteLink = Form::deleteajax(url()->route('brand.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'), $query->title);
26
                $links = '<a href="'.url()->route('brand.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
27
            
28
                return $links;
29
            });
30
31
            return $datatables->make(true);
32
        }
33
        
34
        return view('backend.brand.index')->with('brand', BrandService::selectAll());
35
    }
36
37
    public function create()
38
    {
39
        return view('backend.brand.create')->with(array());
40
    }
41
42
    public function store(Request $request)
43
    {
44
        $result  = BrandService::create($request->all());
45
        return BrandService::notificationRedirect('brand.index', $result, 'The brand was inserted.');
46
    }
47
48
    public function edit($brandId)
49
    {
50
        return view('backend.brand.edit')->with(array('brand' => BrandService::find($brandId)));
51
    }
52
53
    public function update(Request $request, $brandId)
54
    {
55
        $result  = BrandService::updateById($request->all(), $brandId);
56
        return BrandService::notificationRedirect('brand.index', $result, 'The brand was updated.');
57
    }
58
59
    public function destroy($brandId)
60
    {
61
        $result  = BrandService::destroy($brandId);
62
        if ($result) {
63
            flash('The brand was deleted.');
64
            return redirect()->route('brand.index');
65
        }
66
    }
67
}
68