@@ -70,13 +70,13 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = [])
7070
7171 public function prepareOrders (RestifyRequest $ request , $ query , $ extra = [])
7272 {
73- $ sort = $ request ->get ('sort ' , '' );
73+ $ orderings = explode ( ' , ' , $ request ->get ('sort ' , '' ) );
7474
7575 if (isset ($ extra ['sort ' ])) {
76- $ sort = $ extra ['sort ' ];
76+ $ orderings = $ extra ['sort ' ];
7777 }
7878
79- $ params = explode ( ' , ' , $ sort );
79+ $ params = array_filter ( $ orderings );
8080
8181 if (is_array ($ params ) === true && empty ($ params ) === false ) {
8282 foreach ($ params as $ param ) {
@@ -85,7 +85,7 @@ public function prepareOrders(RestifyRequest $request, $query, $extra = [])
8585 }
8686
8787 if (empty ($ params ) === true ) {
88- $ this ->setOrder ($ query , '+id ' );
88+ $ this ->setOrder ($ query , '+ ' . $ this -> repository -> newModel ()-> getKeyName () );
8989 }
9090
9191 return $ query ;
@@ -107,6 +107,11 @@ public function prepareRelations(RestifyRequest $request, $query, $extra = [])
107107 public function prepareSearchFields (RestifyRequest $ request , $ query , $ extra = [])
108108 {
109109 $ search = $ request ->get ('search ' , data_get ($ extra , 'search ' , '' ));
110+
111+ if (empty ($ search )) {
112+ return $ query ;
113+ }
114+
110115 $ model = $ query ->getModel ();
111116
112117 $ query ->where (function ($ query ) use ($ search , $ model ) {
@@ -154,6 +159,8 @@ public function setOrder($query, $param)
154159 $ field = $ param ;
155160 }
156161
162+ $ field = $ field ?? $ this ->repository ->newModel ()->getKeyName ();
163+
157164 if (isset ($ field )) {
158165 if (in_array ($ field , $ this ->repository ->getOrderByFields ()) === true ) {
159166 if ($ order === '- ' ) {
0 commit comments