|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ProductCategoryImageController |
|
5
|
|
|
* |
|
6
|
|
|
* This is the controller of the product category images of the shop |
|
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 DataTables; |
|
14
|
|
|
use Form; |
|
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService; |
|
16
|
|
|
|
|
17
|
|
|
class ProductCategoryImageController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
public function index(Request $request, $productCategoryId) |
|
20
|
|
|
{ |
|
21
|
|
|
$productCategory = ProductCategoryService::find($productCategoryId); |
|
22
|
|
|
if ($request->wantsJson()) { |
|
23
|
|
|
|
|
24
|
|
|
$image = ProductCategoryService::getImageModel()->where('product_category_id', '=', $productCategoryId); |
|
25
|
|
|
|
|
26
|
|
|
$datatables = DataTables::of($image) |
|
27
|
|
|
|
|
28
|
|
|
->addColumn('thumb', function ($image) use ($productCategoryId) { |
|
|
|
|
|
|
29
|
|
|
return '<img src="/files/product_category/100x100/'.$image->product_category_id.'/'.$image->file.'" />'; |
|
30
|
|
|
}) |
|
31
|
|
|
->addColumn('action', function ($image) use ($productCategoryId) { |
|
32
|
|
|
$deleteLink = Form::deleteajax(url()->route('product-category.images.destroy', array('productCategoryId' => $productCategoryId, 'id' => $image->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
33
|
|
|
$links = '<a href="'.url()->route('product-category.images.edit', array('productCategoryId' => $productCategoryId, 'id' => $image->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
|
34
|
|
|
return $links; |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
return $datatables->make(true); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return view('backend.product_category_image.index')->with(array('productCategory' => $productCategory)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function create($productCategoryId) |
|
44
|
|
|
{ |
|
45
|
|
|
$productCategory = ProductCategoryService::find($productCategoryId); |
|
46
|
|
|
return view('backend.product_category_image.create')->with(array('productCategory' => $productCategory)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function store(Request $request, $productCategoryId) |
|
50
|
|
|
{ |
|
51
|
|
|
$result = ProductCategoryService::createImage($request->all(), $productCategoryId); |
|
52
|
|
|
return ProductCategoryService::notificationRedirect(array('product-category.images.index', $productCategoryId), $result, 'The category image was inserted.'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function edit(Request $request, $productCategoryId, $productCategoryImageId) |
|
56
|
|
|
{ |
|
57
|
|
|
$productCategory = ProductCategoryService::find($productCategoryId); |
|
58
|
|
|
return view('backend.product_category_image.edit')->with(array('productCategoryImage' => ProductCategoryService::findImage($productCategoryImageId), 'productCategory' => $productCategory)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function update(Request $request, $productCategoryId, $productCategoryImageId) |
|
62
|
|
|
{ |
|
63
|
|
|
$result = ProductCategoryService::updateImageById($request->all(), $productCategoryId, $productCategoryImageId); |
|
64
|
|
|
return ProductCategoryService::notificationRedirect(array('product-category.images.index', $productCategoryId), $result, 'The category image was updated.'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function destroy($productCategoryId, $productCategoryImageId) |
|
68
|
|
|
{ |
|
69
|
|
|
$result = ProductCategoryService::destroyImage($productCategoryImageId); |
|
70
|
|
|
|
|
71
|
|
|
if ($result) { |
|
72
|
|
|
flash('The file was deleted.'); |
|
73
|
|
|
return redirect()->route('product-category.images.index', $productCategoryId); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for imports that have been defined, but are not used in the scope.