@@ -32,7 +32,7 @@ abstract class Repository implements RepositoryInterface
32
32
function __construct (Application $ app ) {
33
33
$ this ->app = $ app ;
34
34
$ this ->makeModel ();
35
- $ this ->relations = $ this ->model ->_relations ;
35
+ $ this ->relations = ( $ this ->model ->_relations ? $ this -> model -> _relations : [] ) ;
36
36
}
37
37
38
38
/**
@@ -44,15 +44,15 @@ abstract function model();
44
44
/**
45
45
* Function to create the instance of Eloquent Model
46
46
* @return Model
47
- * @throws Exception
47
+ * @throws \ Exception
48
48
*/
49
49
public function makeModel ()
50
50
{
51
51
$ name_model = $ this ->model ();
52
52
$ model = $ this ->app ->make ($ name_model );
53
53
54
54
if (!$ model instanceof Model) {
55
- throw new Exception ("Class { $ name_model } must be an instance of Illuminate \\Database \\Eloquent \\Model " );
55
+ throw new \ Exception ("Class { $ name_model } must be an instance of Illuminate \\Database \\Eloquent \\Model " );
56
56
}
57
57
58
58
return $ this ->model = $ model ;
@@ -110,15 +110,15 @@ public function takeByWithRelations($limit, $field, $value)
110
110
public function takeRandomByWithRelations ($ limit , $ field , $ value )
111
111
{
112
112
return $ this ->model ->with ($ this ->relations )->where ($ field , $ value )
113
- ->orderBy (DB ::raw ('RAND() ' ))->get ()->take ($ limit );
113
+ ->orderBy (DB ::raw ('RAND() ' ))->get ()->take ($ limit );
114
114
}
115
115
116
116
/**
117
117
* Return all rows with relations
118
118
* @param array $columns
119
- * @param array $where
119
+ * @return mixed
120
120
*/
121
- public function allWithRelations ($ columns = array ('* ' ), $ where = array () )
121
+ public function allWithRelations ($ columns = array ('* ' ))
122
122
{
123
123
return $ this ->model ->with ($ this ->relations )->get ($ columns );
124
124
}
@@ -145,6 +145,18 @@ public function paginateWithAllRelations($perPage = 10, $columns = array('*'))
145
145
return $ this ->model ->with ($ this ->relations )->paginate ($ perPage , $ columns );
146
146
}
147
147
148
+ public function paginateByFiltersWithAllRelations ($ filters = array (), $ perPage = 10 , $ columns = array ('* ' ))
149
+ {
150
+ $ query = $ this ->model ->with ($ this ->relations );
151
+
152
+ foreach ($ filters as $ field => $ value ) {
153
+ $ query ->where ($ field , $ value );
154
+ }
155
+
156
+ return $ query ->get ($ columns );
157
+ }
158
+
159
+
148
160
/**
149
161
* Create a record of model
150
162
* @param array $data
@@ -185,11 +197,11 @@ public function delete($entity)
185
197
{
186
198
if (is_numeric ($ entity ))
187
199
{
188
- $ this ->model ->destroy ($ entity );
200
+ $ this ->model ->destroy ($ entity );
189
201
}
190
202
else {
191
- $ entity = $ this ->findOrFail ($ entity );
192
- $ entity ->delete ();
203
+ $ entity = $ this ->findOrFail ($ entity );
204
+ $ entity ->delete ();
193
205
}
194
206
return true ;
195
207
}
0 commit comments