|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ExtraFieldController |
|
5
|
|
|
* |
|
6
|
|
|
* This is the controller of the product weight types of the shop |
|
7
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
|
8
|
|
|
* @version 0.1 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
use App\Http\Controllers\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Hideyo\Ecommerce\Framework\Services\ExtraField\ExtraFieldFacade as ExtraFieldService; |
|
14
|
|
|
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService; |
|
15
|
|
|
|
|
16
|
|
|
use Illuminate\Http\Request; |
|
17
|
|
|
use DataTables; |
|
18
|
|
|
use Form; |
|
19
|
|
|
|
|
20
|
|
|
class ExtraFieldController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
public function index(Request $request) |
|
23
|
|
|
{ |
|
24
|
|
|
if ($request->wantsJson()) { |
|
25
|
|
|
|
|
26
|
|
|
$query = ExtraFieldService::getModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$datatables = DataTables::of($query) |
|
29
|
|
|
|
|
30
|
|
|
->addColumn('category', function ($query) { |
|
31
|
|
|
if ($query->categories) { |
|
32
|
|
|
$output = array(); |
|
33
|
|
|
foreach ($query->categories as $categorie) { |
|
34
|
|
|
$output[] = $categorie->title; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return implode(' | ', $output); |
|
38
|
|
|
} |
|
39
|
|
|
}) |
|
40
|
|
|
|
|
41
|
|
|
->addColumn('action', function ($query) { |
|
42
|
|
|
$deleteLink = Form::deleteajax(url()->route('extra-field.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
43
|
|
|
$links = '<a href="'.url()->route('extra-field.values.index', $query->id).'" class="btn btn-default btn-sm btn-info"><i class="entypo-pencil"></i>'.$query->values->count().' values</a> |
|
44
|
|
|
<a href="'.url()->route('extra-field.edit', $query->id).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> |
|
45
|
|
|
'.$deleteLink; |
|
46
|
|
|
|
|
47
|
|
|
return $links; |
|
48
|
|
|
}); |
|
49
|
|
|
|
|
50
|
|
|
return $datatables->make(true); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return view('backend.extra-field.index')->with('extraField', ExtraFieldService::selectAll()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function create() |
|
57
|
|
|
{ |
|
58
|
|
|
return view('backend.extra-field.create')->with(array('productCategories' => ProductCategoryService::selectAll()->pluck('title', 'id'))); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function store(Request $request) |
|
62
|
|
|
{ |
|
63
|
|
|
$result = ExtraFieldService::create($request->all()); |
|
64
|
|
|
return ExtraFieldService::notificationRedirect('extra-field.index', $result, 'The extra field was inserted.'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function edit($id) |
|
68
|
|
|
{ |
|
69
|
|
|
return view('backend.extra-field.edit')->with(array('extraField' => ExtraFieldService::find($id), 'productCategories' => ProductCategoryService::selectAll()->pluck('title', 'id'))); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function update(Request $request, $id) |
|
73
|
|
|
{ |
|
74
|
|
|
$result = ExtraFieldService::updateById($request->all(), $id); |
|
75
|
|
|
return ExtraFieldService::notificationRedirect('extra-field.index', $result, 'The extra field was updated.'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function destroy($id) |
|
79
|
|
|
{ |
|
80
|
|
|
$result = ExtraFieldService::destroy($id); |
|
81
|
|
|
|
|
82
|
|
|
if ($result) { |
|
83
|
|
|
flash('Extra field was deleted.'); |
|
84
|
|
|
return redirect()->route('extra-field.index'); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|