@@ -382,8 +382,21 @@ public function index()
382
382
383
383
if (empty ($ this ->getValidationRules )) {
384
384
if ($ get = input ()->get ()) {
385
+ if ($ scopes = $ get ->offsetGet ('scopes ' )) {
386
+ $ get ->offsetUnset ('scopes ' );
387
+ $ scopes = explode (', ' , $ scopes );
388
+ $ scopes = array_map ('trim ' , $ scopes );
389
+ $ scopes = array_filter ($ scopes );
390
+
391
+ $ this ->model ->appendColumns = $ scopes ;
392
+ }
393
+
385
394
if (false !== ($ result = $ this ->model ->findWhere ($ get ->getArrayCopy (), $ limit ))) {
386
395
if ($ result ->count ()) {
396
+ if ($ get ->offsetExists ('id ' )) {
397
+ $ result = $ result ->first ();
398
+ }
399
+
387
400
$ this ->sendPayload ($ result );
388
401
} else {
389
402
$ this ->sendError (204 );
@@ -397,22 +410,27 @@ public function index()
397
410
$ this ->sendError (204 );
398
411
}
399
412
} elseif ($ get = input ()->get ()) {
400
- $ get ->validation ($ this ->getValidationRules , $ this ->getValidationCustomErrors );
413
+ if ($ scopes = $ get ->offsetGet ('scopes ' )) {
414
+ $ get ->offsetUnset ('scopes ' );
415
+ $ scopes = explode (', ' , $ scopes );
416
+ $ scopes = array_map ('trim ' , $ scopes );
417
+ $ scopes = array_filter ($ scopes );
401
418
402
- if ( ! $ get ->validate ()) {
403
- $ this ->sendError (400 , implode (', ' , $ get ->validator ->getErrors ()));
419
+ $ this ->model ->appendColumns = $ scopes ;
404
420
}
405
421
406
- $ conditions = [] ;
422
+ $ get -> validation ( $ this -> getValidationRules , $ this -> getValidationCustomErrors ) ;
407
423
408
- foreach ($ this ->getValidationRules as $ field => $ rule ) {
409
- if ($ get ->offsetExists ($ field )) {
410
- $ conditions [ $ field ] = $ get ->offsetGet ($ field );
411
- }
424
+ if ( ! $ get ->validate ()) {
425
+ $ this ->sendError (400 , implode (', ' , $ get ->validator ->getErrors ()));
412
426
}
413
427
414
- if (false !== ($ result = $ this ->model ->findWhere ($ conditions , $ limit ))) {
428
+ if (false !== ($ result = $ this ->model ->findWhere ($ get -> getArrayCopy () , $ limit ))) {
415
429
if ($ result ->count ()) {
430
+ if ($ get ->offsetExists ('id ' )) {
431
+ $ result = $ result ->first ();
432
+ }
433
+
416
434
$ this ->sendPayload ($ result );
417
435
} else {
418
436
$ this ->sendError (204 );
@@ -544,14 +562,6 @@ public function create()
544
562
}
545
563
}
546
564
547
- if (count ($ this ->fillableColumns )) {
548
- foreach ($ this ->fillableColumns as $ column ) {
549
- if ($ post ->offsetExists ($ column )) {
550
- $ data [ $ column ] = $ post ->offsetGet ($ column );
551
- }
552
- }
553
- }
554
-
555
565
if (count ($ data )) {
556
566
$ data [ 'record_create_timestamp ' ] = $ data [ 'record_update_timestamp ' ] = timestamp ();
557
567
@@ -654,14 +664,6 @@ public function update()
654
664
}
655
665
}
656
666
657
- if (count ($ this ->fillableColumns )) {
658
- foreach ($ this ->fillableColumns as $ column ) {
659
- if ($ post ->offsetExists ($ column )) {
660
- $ data [ $ column ] = $ post ->offsetGet ($ column );
661
- }
662
- }
663
- }
664
-
665
667
if (count ($ data )) {
666
668
$ data [ 'record_update_timestamp ' ] = timestamp ();
667
669
@@ -756,7 +758,7 @@ public function delete($id = null)
756
758
757
759
if ($ result = $ this ->model ->findWhere ($ conditions )) {
758
760
if ($ result instanceof Row) {
759
- if ($ row ->delete ()) {
761
+ if ($ result ->delete ()) {
760
762
$ this ->sendError (200 );
761
763
} else {
762
764
$ this ->sendError (501 );
@@ -827,7 +829,7 @@ public function delete($id = null)
827
829
828
830
if ($ result = $ this ->model ->findWhere ($ conditions )) {
829
831
if ($ result instanceof Row) {
830
- if ($ row ->delete ()) {
832
+ if ($ result ->delete ()) {
831
833
$ this ->sendError (200 );
832
834
} else {
833
835
$ this ->sendError (501 );
@@ -905,7 +907,7 @@ private function updateRecordStatus(array $params, $method)
905
907
906
908
if ($ result = $ this ->model ->findWhere ($ conditions )) {
907
909
if ($ result instanceof Row) {
908
- if ($ row ->{$ method }()) {
910
+ if ($ result ->{$ method }()) {
909
911
$ this ->sendError (200 );
910
912
} else {
911
913
$ this ->sendError (501 );
@@ -979,7 +981,7 @@ private function updateRecordStatus(array $params, $method)
979
981
980
982
if ($ result = $ this ->model ->findWhere ($ conditions )) {
981
983
if ($ result instanceof Row) {
982
- if ($ row ->{$ method }()) {
984
+ if ($ result ->{$ method }()) {
983
985
$ this ->sendError (200 );
984
986
} else {
985
987
$ this ->sendError (501 );
0 commit comments