7
7
use AvoRed \Ecommerce \DataGrid \Attribute ;
8
8
use AvoRed \Framework \Models \Database \Attribute as Model ;
9
9
use AvoRed \Ecommerce \Http \Requests \AttributeRequest ;
10
+ use AvoRed \Framework \Models \Contracts \AttributeInterface ;
10
11
11
12
class AttributeController extends Controller
12
13
{
14
+ /**
15
+ *
16
+ * @var \AvoRed\Framework\Models\Repository\AttributeRepository
17
+ */
18
+ protected $ repository ;
19
+
20
+ public function __construct (AttributeInterface $ repository )
21
+ {
22
+ $ this ->repository = $ repository ;
23
+ }
13
24
14
25
/**
15
26
* Display a listing of the resource.
@@ -18,7 +29,7 @@ class AttributeController extends Controller
18
29
*/
19
30
public function index ()
20
31
{
21
- $ attributeGrid = new Attribute (Model:: query ());
32
+ $ attributeGrid = new Attribute ($ this -> repository -> query ());
22
33
23
34
return view ('avored-ecommerce::attribute.index ' )->with ('dataGrid ' , $ attributeGrid ->dataGrid );
24
35
}
@@ -35,20 +46,20 @@ public function create()
35
46
36
47
/**
37
48
* @param \AvoRed\Ecommerce\Http\Requests\AttributeRequest $request
38
- *
49
+ *
39
50
* @return \Illuminate\Http\RedirectResponse
40
51
*/
41
52
public function store (AttributeRequest $ request )
42
53
{
43
- $ attribute = Model:: create ($ request ->all ());
54
+ $ attribute = $ this -> repository -> create ($ request ->all ());
44
55
$ this ->_saveDropdownOptions ($ attribute , $ request );
45
56
46
57
return redirect ()->route ('admin.attribute.index ' );
47
58
}
48
59
49
60
/**
50
61
* @param \AvoRed\Framework\Models\Database\Attribute $attribute
51
- *
62
+ *
52
63
* @return \Illuminate\Http\RedirectResponse
53
64
*/
54
65
public function edit (Model $ attribute )
@@ -76,7 +87,7 @@ public function destroy(Model $attribute)
76
87
77
88
/**
78
89
* Get an attribute for Product Variation Modal.
79
- *
90
+ *
80
91
* @param \Illuminate\Http\Request
81
92
* @return \Illuminate\Http\Response
82
93
*/
@@ -97,7 +108,7 @@ public function getAttribute(Request $request)
97
108
*/
98
109
public function getElementHtml (Request $ request )
99
110
{
100
- $ attributes = Model:: whereIn ( ' id ' , $ request ->get ('attribute_id ' ))-> get ( );
111
+ $ attributes = $ this -> repository -> findMany ( $ request ->get ('attribute_id ' ));
101
112
102
113
$ tmpString = '__RANDOM__STRING__ ' ;
103
114
$ view = view ('avored-ecommerce::attribute.get-element ' )
@@ -117,10 +128,9 @@ public function getElementHtml(Request $request)
117
128
private function _saveDropdownOptions ($ attribute , $ request )
118
129
{
119
130
if (null !== $ request ->get ('dropdown-options ' )) {
120
- if (null != $ attribute ->attributeDropdownOptions ()->get () &&
131
+ if (null != $ attribute ->attributeDropdownOptions ()->get () &&
121
132
$ attribute ->attributeDropdownOptions ()->get ()->count () >= 0
122
133
) {
123
-
124
134
$ attribute ->attributeDropdownOptions ()->delete ();
125
135
}
126
136
@@ -133,4 +143,4 @@ private function _saveDropdownOptions($attribute, $request)
133
143
}
134
144
}
135
145
}
136
- }
146
+ }
0 commit comments