@@ -32,7 +32,7 @@ abstract class Repository implements RepositoryInterface
3232 function __construct (Application $ app ) {
3333 $ this ->app = $ app ;
3434 $ this ->makeModel ();
35- $ this ->relations = $ this ->model ->_relations ;
35+ $ this ->relations = ( $ this ->model ->_relations ? $ this -> model -> _relations : [] ) ;
3636 }
3737
3838 /**
@@ -44,15 +44,15 @@ abstract function model();
4444 /**
4545 * Function to create the instance of Eloquent Model
4646 * @return Model
47- * @throws Exception
47+ * @throws \ Exception
4848 */
4949 public function makeModel ()
5050 {
5151 $ name_model = $ this ->model ();
5252 $ model = $ this ->app ->make ($ name_model );
5353
5454 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 " );
5656 }
5757
5858 return $ this ->model = $ model ;
@@ -110,15 +110,15 @@ public function takeByWithRelations($limit, $field, $value)
110110 public function takeRandomByWithRelations ($ limit , $ field , $ value )
111111 {
112112 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 );
114114 }
115115
116116 /**
117117 * Return all rows with relations
118118 * @param array $columns
119- * @param array $where
119+ * @return mixed
120120 */
121- public function allWithRelations ($ columns = array ('* ' ), $ where = array () )
121+ public function allWithRelations ($ columns = array ('* ' ))
122122 {
123123 return $ this ->model ->with ($ this ->relations )->get ($ columns );
124124 }
@@ -145,6 +145,18 @@ public function paginateWithAllRelations($perPage = 10, $columns = array('*'))
145145 return $ this ->model ->with ($ this ->relations )->paginate ($ perPage , $ columns );
146146 }
147147
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+
148160 /**
149161 * Create a record of model
150162 * @param array $data
@@ -185,11 +197,11 @@ public function delete($entity)
185197 {
186198 if (is_numeric ($ entity ))
187199 {
188- $ this ->model ->destroy ($ entity );
200+ $ this ->model ->destroy ($ entity );
189201 }
190202 else {
191- $ entity = $ this ->findOrFail ($ entity );
192- $ entity ->delete ();
203+ $ entity = $ this ->findOrFail ($ entity );
204+ $ entity ->delete ();
193205 }
194206 return true ;
195207 }
0 commit comments