1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AttributeController |
5
|
|
|
* |
6
|
|
|
* This is the controller of the attributes of a attribute group |
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
|
|
|
|
16
|
|
|
use Hideyo\Ecommerce\Framework\Services\Attribute\AttributeFacade as AttributeService; |
17
|
|
|
|
18
|
|
|
class AttributeController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Display a listing of the resource. |
22
|
|
|
* @param \Illuminate\Http\Request $request |
23
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
24
|
|
|
* @return View |
|
|
|
|
25
|
|
|
* @return datatables |
26
|
|
|
*/ |
27
|
|
|
public function index(Request $request, $attributeGroupId) |
28
|
|
|
{ |
29
|
|
|
if ($request->wantsJson()) { |
30
|
|
|
$query = AttributeService::getModel()->where('attribute_group_id', '=', $attributeGroupId); |
31
|
|
|
|
32
|
|
|
$datatables = DataTables::of($query) |
33
|
|
|
->addColumn('action', function ($query) use ($attributeGroupId) { |
34
|
|
|
$deleteLink = Form::deleteajax(url()->route('attribute.destroy', array('attributeGroupId' => $attributeGroupId, 'id' => $query->id)), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
35
|
|
|
$links = ' <a href="'.url()->route('attribute.edit', array('attributeGroupId' => $attributeGroupId, 'id' => $query->id)).'" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>'.$deleteLink; |
36
|
|
|
return $links; |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
return $datatables->make(true); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return view('backend.attribute.index') |
|
|
|
|
43
|
|
|
->with('attributeGroup', AttributeService::findGroup($attributeGroupId)); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Show the form for creating a new resource. |
48
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
49
|
|
|
* @return view |
|
|
|
|
50
|
|
|
*/ |
51
|
|
|
public function create($attributeGroupId) |
52
|
|
|
{ |
53
|
|
|
return view('backend.attribute.create')->with(array('attributeGroup' => AttributeService::findGroup($attributeGroupId))); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Store a newly created resource in storage. |
58
|
|
|
* @param \Illuminate\Http\Request $request |
59
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
60
|
|
|
* @return Redirect |
61
|
|
|
*/ |
62
|
|
|
public function store(Request $request, $attributeGroupId) |
63
|
|
|
{ |
64
|
|
|
$result = AttributeService::create($request->all(), $attributeGroupId); |
65
|
|
|
return AttributeService::notificationRedirect(array('attribute.index', $attributeGroupId), $result, 'The attribute was inserted.'); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Show the form for editing the specified resource. |
70
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
71
|
|
|
* @param int $attributeId |
72
|
|
|
* @return Redirect |
73
|
|
|
*/ |
74
|
|
|
public function edit($attributeGroupId, $attributeId) |
75
|
|
|
{ |
76
|
|
|
return view('backend.attribute.edit')->with(array('attributeGroupId' => $attributeGroupId, 'attribute' => AttributeService::find($attributeId))); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Update the specified resource in storage. |
81
|
|
|
* @param \Illuminate\Http\Request $request |
82
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
83
|
|
|
* @param int $attributeId |
84
|
|
|
* @return Redirect |
85
|
|
|
*/ |
86
|
|
|
public function update(Request $request, $attributeGroupId, $attributeId) |
87
|
|
|
{ |
88
|
|
|
$result = AttributeService::updateById($request->all(), $attributeGroupId, $attributeId); |
89
|
|
|
return AttributeService::notificationRedirect(array('attribute.index', $attributeGroupId), $result, 'The attribute was updated.'); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Remove the specified resource from storage |
94
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
95
|
|
|
* @param int $attributeId |
96
|
|
|
* @return Redirect |
97
|
|
|
*/ |
98
|
|
|
public function destroy($attributeGroupId, $attributeId) |
99
|
|
|
{ |
100
|
|
|
$result = AttributeService::destroy($attributeId); |
101
|
|
|
|
102
|
|
|
if ($result) { |
103
|
|
|
flash('Atrribute was deleted.'); |
104
|
|
|
return redirect()->route('attribute.index', $attributeGroupId); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |