|
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 DataTables; |
|
13
|
|
|
use Form; |
|
14
|
|
|
|
|
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\Brand\BrandFacade as BrandService; |
|
16
|
|
|
|
|
17
|
|
|
class BrandImageController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
public function index(Request $request, $brandId) |
|
20
|
|
|
{ |
|
21
|
|
|
$brand = BrandService::find($brandId); |
|
22
|
|
|
if ($request->wantsJson()) { |
|
23
|
|
|
$image = BrandService::getModelImage()->where('brand_id', '=', $brandId); |
|
24
|
|
|
|
|
25
|
|
|
$datatables = DataTables::of($image) |
|
26
|
|
|
->addColumn('thumb', function ($image) { |
|
27
|
|
|
return '<img src="'.config('hideyo.public_path').'/brand/100x100/'.$image->brand_id.'/'.$image->file.'" />'; |
|
28
|
|
|
}) |
|
29
|
|
|
->addColumn('action', function ($image) use ($brandId) { |
|
30
|
|
|
$deleteLink = Form::deleteajax(url()->route('brand.images.destroy', array('brandId' => $brandId, 'id' => $image->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
31
|
|
|
$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; |
|
32
|
|
|
return $links; |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
return $datatables->make(true); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return view('backend.brand_image.index')->with(array( 'brand' => $brand)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function create($brandId) |
|
42
|
|
|
{ |
|
43
|
|
|
$brand = BrandService::find($brandId); |
|
44
|
|
|
return view('backend.brand_image.create')->with(array('brand' => $brand)); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function store(Request $request, $brandId) |
|
48
|
|
|
{ |
|
49
|
|
|
$result = BrandService::createImage($request->all(), $brandId); |
|
50
|
|
|
return BrandService::notificationRedirect(array('brand.images.index', $brandId), $result, 'The brand image was inserted.'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function edit($brandId, $brandImageId) |
|
54
|
|
|
{ |
|
55
|
|
|
$brand = BrandService::find($brandId); |
|
56
|
|
|
return view('backend.brand_image.edit')->with(array('brandImage' => BrandService::findImage($brandImageId), 'brand' => $brand)); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function update(Request $request, $brandId, $brandImageId) |
|
60
|
|
|
{ |
|
61
|
|
|
$result = BrandService::updateImageById($request->all(), $brandId, $brandImageId); |
|
62
|
|
|
return BrandService::notificationRedirect(array('brand.images.index', $brandId), $result, 'The brand image was updated.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function destroy($brandId, $brandImageId) |
|
66
|
|
|
{ |
|
67
|
|
|
$result = BrandService::destroyImage($brandImageId); |
|
68
|
|
|
|
|
69
|
|
|
if ($result) { |
|
70
|
|
|
flash('The file was deleted.'); |
|
71
|
|
|
return redirect()->route('brand.images.index', $brandId); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |