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

BrandImageController::__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
 * BrandImageController
4
 *
5
 * This is the controller for the images of a brand item
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 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...
14
use Form;
15
16
use Hideyo\Ecommerce\Framework\Services\Brand\BrandFacade as BrandService;
17
18
class BrandImageController extends Controller
19
{
20
    public function index(Request $request, $brandId)
21
    {
22
        $brand = BrandService::find($brandId);
23
        if ($request->wantsJson()) {
24
25
            $image = BrandService::getModelImage()
26
            ->select(['id','file', 'brand_id'])
27
            ->where('brand_id', '=', $brandId);
28
            
29
            $datatables = Datatables::of($image)
30
31
            ->addColumn('thumb', function ($image) use ($brandId) {
0 ignored issues
show
Unused Code introduced by
The import $brandId is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
32
                return '<img src="'.config('hideyo.public_path').'/brand/100x100/'.$image->brand_id.'/'.$image->file.'"  />';
33
            })
34
            ->addColumn('action', function ($image) use ($brandId) {
35
                $deleteLink = Form::deleteajax(url()->route('brand.images.destroy', array('brandId' => $brandId, 'id' => $image->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
36
                $links = '<a href="'.url()->route('brand.images.edit', array('brandId' => $brandId, 'id' => $image->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
37
                return $links;
38
            });
39
40
            return $datatables->make(true);
41
        }
42
        
43
        return view('backend.brand_image.index')->with(array( 'brand' => $brand));
44
    }
45
46
    public function create($brandId)
47
    {
48
        $brand = BrandService::find($brandId);
49
        return view('backend.brand_image.create')->with(array('brand' => $brand));
50
    }
51
52
    public function store(Request $request, $brandId)
53
    {
54
        $result  = BrandService::createImage($request->all(), $brandId);
55
        return BrandService::notificationRedirect(array('brand.images.index', $brandId), $result, 'The brand image was inserted.');
56
    }
57
58
    public function edit($brandId, $brandImageId)
59
    {
60
        $brand = BrandService::find($brandId);
61
        return view('backend.brand_image.edit')->with(array('brandImage' => BrandService::findImage($brandImageId), 'brand' => $brand));
62
    }
63
64
    public function update(Request $request, $brandId, $brandImageId)
65
    {
66
        $result  = BrandService::updateImageById($request->all(), $brandId, $brandImageId);
67
        return BrandService::notificationRedirect(array('brand.images.index', $brandId), $result, 'The brand image was updated.');
68
    }
69
70
    public function destroy($brandId, $brandImageId)
71
    {
72
        $result  = BrandService::destroyImage($brandImageId);
73
74
        if ($result) {
75
            Notification::success('The file was deleted.');
76
            return redirect()->route('brand.images.index', $brandId);
77
        }
78
    }
79
}
80