@@ -22,9 +22,9 @@ public function __construct()
2222 /**
2323 * @return mixed
2424 */
25- public function all ()
25+ public function all ($ paginate = null )
2626 {
27- return $ this ->entity -> get ( );
27+ return $ this ->processPagination ( $ this -> entity , $ paginate );
2828 }
2929
3030 /**
@@ -50,9 +50,11 @@ public function find($id)
5050 * @param $value
5151 * @return mixed
5252 */
53- public function findWhere ($ column , $ value )
53+ public function findWhere ($ column , $ value, $ paginate = null )
5454 {
55- return $ this ->entity ->where ($ column , $ value )->get ();
55+ $ query = $ this ->entity ->where ($ column , $ value );
56+
57+ return $ this ->processPagination ($ query , $ paginate );
5658 }
5759
5860 /**
@@ -76,23 +78,19 @@ public function findWhereFirst($column, $value)
7678 /**
7779 * {@inheritdoc}
7880 */
79- public function findWhereLike ($ column , $ value , $ paginate = 0 )
81+ public function findWhereLike ($ columns , $ value , $ paginate = null )
8082 {
81- $ query = $ this ->entity ;
82- if (is_array ($ column )) {
83- $ i = 0 ;
84- foreach ($ column as $ columnItem ) {
85- if ($ i == 0 ) {
86- $ query ->where ($ column , 'like ' , $ value );
87- } else {
88- $ query ->orWhere ($ column , 'like ' , $ value );
89- }
90- $ i ++;
91- }
92- } else {
93- $ query ->where ($ column , 'like ' , $ value );
83+ $ query = $ this ->entity ;
84+
85+ if (is_string ($ columns )) {
86+ $ columns = [$ columns ];
9487 }
95- return $ paginate > 0 ? $ query ->paginate ($ paginate ) : $ query ->get ();
88+
89+ foreach ($ columns as $ column ) {
90+ $ query ->orWhere ($ column , 'like ' , $ value );
91+ }
92+
93+ return $ this ->processPagination ($ query , $ paginate );
9694 }
9795
9896 /**
@@ -155,4 +153,9 @@ protected function resolveEntity()
155153
156154 return app ($ this ->entity ());
157155 }
156+
157+ private function processPagination ($ query , $ paginate )
158+ {
159+ return $ paginate ? $ query ->paginate ($ paginate ) : $ query ->get ();
160+ }
158161}
0 commit comments