@@ -199,7 +199,7 @@ public function find($id, $columns = ['*'])
199199 * Find a model by its primary key or throw an exception.
200200 *
201201 * @param string $id
202- * @param array $columns
202+ * @param array $columns
203203 *
204204 * @return \Illuminate\Database\Eloquent\Model
205205 *
@@ -269,8 +269,7 @@ public function findWhere(array $where, $columns = ['*'])
269269 if (is_array ($ value )) {
270270 list ($ field , $ condition , $ val ) = $ value ;
271271 $ this ->query ->where ($ field , $ condition , $ val );
272- }
273- else {
272+ } else {
274273 $ this ->query ->where ($ field , '= ' , $ value );
275274 }
276275 }
@@ -327,9 +326,21 @@ public function getOrderBy()
327326 */
328327 public function getSearchableKeys ()
329328 {
329+ $ return = $ this ->getSearchable ();
330+
330331 return array_values (array_map (function ($ value , $ key ) {
331332 return (is_array ($ value ) || is_numeric ($ key ) === false ) ? $ key : $ value ;
332- }, $ this ->searchable , array_keys ($ this ->searchable )));
333+ }, $ return , array_keys ($ return )));
334+ }
335+
336+ /**
337+ * Return searchable array.
338+ *
339+ * @return array
340+ */
341+ public function getSearchable ()
342+ {
343+ return $ this ->searchable ;
333344 }
334345
335346 /**
@@ -352,7 +363,7 @@ public function search($queries)
352363 // Keep track of what tables have been joined and their aliases
353364 $ joined = [];
354365
355- foreach ($ this ->searchable as $ param => $ columns ) {
366+ foreach ($ this ->getSearchable () as $ param => $ columns ) {
356367 // It doesn't always have to map to something
357368 $ param = is_numeric ($ param ) ? $ columns : $ param ;
358369
@@ -363,7 +374,7 @@ public function search($queries)
363374 if ($ value === '' || $ value === null ) continue ;
364375
365376 // Columns should be an array
366- $ columns = (array )$ columns ;
377+ $ columns = (array ) $ columns ;
367378
368379 // Loop though the columns and look for relationships
369380 foreach ($ columns as $ key => $ column ) {
@@ -401,8 +412,7 @@ public function search($queries)
401412 $ this ->createSearchClause ($ q , $ param , $ column , $ value , 'or ' );
402413 }
403414 });
404- }
405- else {
415+ } else {
406416 $ this ->createSearchClause ($ query , $ param , $ columns [0 ], $ value );
407417 }
408418 }
@@ -482,10 +492,10 @@ public function pluck($value, $key = null)
482492 /**
483493 * Retrieve all data of repository, paginated
484494 *
485- * @param int $per_page
486- * @param array $columns
487- * @param string $page_name
488- * @param int|null $page
495+ * @param int $per_page
496+ * @param array $columns
497+ * @param string $page_name
498+ * @param int|null $page
489499 *
490500 * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
491501 */
@@ -511,10 +521,10 @@ public function paginate($per_page = null, $columns = ['*'], $page_name = 'page'
511521 /**
512522 * Retrieve all data of repository, paginated
513523 *
514- * @param int $per_page
515- * @param array $columns
516- * @param string $page_name
517- * @param int|null $page
524+ * @param int $per_page
525+ * @param array $columns
526+ * @param string $page_name
527+ * @param int|null $page
518528 *
519529 * @return \Illuminate\Contracts\Pagination\Paginator
520530 */
@@ -716,7 +726,7 @@ protected function appendTableName($column)
716726 }
717727
718728 // Remove alias prefix indicator
719- if (substr ( $ column , 0 , 2 ) === ' _. ' ) {
729+ if (preg_match ( ' /^_\./ ' , $ column ) != false ) {
720730 return preg_replace ('/^_\./ ' , '' , $ column );
721731 }
722732
@@ -736,11 +746,9 @@ protected function createSearchClause(Builder $query, $param, $column, $value, $
736746 {
737747 if ($ param === 'query ' ) {
738748 $ query ->where ($ this ->appendTableName ($ column ), self ::$ searchOperator , '% ' . $ value . '% ' , $ boolean );
739- }
740- elseif (is_array ($ value )) {
749+ } elseif (is_array ($ value )) {
741750 $ query ->whereIn ($ this ->appendTableName ($ column ), $ value , $ boolean );
742- }
743- else {
751+ } else {
744752 $ query ->where ($ this ->appendTableName ($ column ), '= ' , $ value , $ boolean );
745753 }
746754 }
0 commit comments