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

BrandController::__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
 * 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 Notification;
13
use Form;
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
16
use Hideyo\Ecommerce\Framework\Services\Brand\BrandFacade as BrandService;
17
18
class BrandController extends Controller
19
{
20
    public function index(Request $request)
21
    {
22
        if ($request->wantsJson()) {
23
            $brand = BrandService::getModel()
24
            ->select(['id', 'rank','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($brand)->addColumn('action', function ($query) {
28
                $deleteLink = Form::deleteajax(url()->route('brand.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'), $query->title);
29
                $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;
30
            
31
                return $links;
32
            });
33
34
            return $datatables->make(true);
35
        }
36
        
37
        return view('backend.brand.index')->with('brand', BrandService::selectAll());
38
    }
39
40
    public function create()
41
    {
42
        return view('backend.brand.create')->with(array());
43
    }
44
45
    public function store(Request $request)
46
    {
47
        $result  = BrandService::create($request->all());
48
        return BrandService::notificationRedirect('brand.index', $result, 'The brand was inserted.');
49
    }
50
51
    public function edit($brandId)
52
    {
53
        return view('backend.brand.edit')->with(array('brand' => BrandService::find($brandId)));
54
    }
55
56
    public function update(Request $request, $brandId)
57
    {
58
        $result  = BrandService::updateById($request->all(), $brandId);
59
        return BrandService::notificationRedirect('brand.index', $result, 'The brand was updated.');
60
    }
61
62
    public function destroy($brandId)
63
    {
64
        $result  = BrandService::destroy($brandId);
65
        if ($result) {
66
            Notification::error('The brand was deleted.');
67
            return redirect()->route('brand.index');
68
        }
69
    }
70
}
71