File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 2
2
composer.phar
3
3
composer.lock
4
4
.DS_Store
5
- .phpintel
5
+ .phpintel
6
+ .idea
Original file line number Diff line number Diff line change 50
50
51
51
'fulltext_score_column ' => '_score ' ,
52
52
53
+ /*
54
+ |--------------------------------------------------------------------------
55
+ | Cleanup Relations in the Response
56
+ |--------------------------------------------------------------------------
57
+ |
58
+ | By default, the API Handler returns all loaded relations of the models,
59
+ | even if they are not in the '_with' param or explicitly loaded with
60
+ | $builder->with(). These unexpected relations can come from custom
61
+ | accessor methods or when you access a relation in your code in general.
62
+ |
63
+ | If you want these to get removed from the response, set this value
64
+ | to true so only the ones in the '_with' param or explicitly added with
65
+ | $builder->with('relation') get returned.
66
+ |
67
+ */
68
+
69
+ 'cleanup_relations ' => false ,
70
+
53
71
/*
54
72
|--------------------------------------------------------------------------
55
73
| Errors
Original file line number Diff line number Diff line change 3
3
use Illuminate \Database \Eloquent \Collection ;
4
4
use Illuminate \Database \Eloquent \Model ;
5
5
use Illuminate \Support \Facades \Response ;
6
+ use \Illuminate \Support \Facades \Config ;
6
7
7
8
class Result
8
9
{
@@ -56,9 +57,17 @@ public function getResponse()
56
57
public function getResult ()
57
58
{
58
59
if ($ this ->parser ->multiple ) {
59
- $ result = $ this ->cleanupRelationsOnModels ($ this ->parser ->builder ->get ());
60
+ $ result = $ this ->parser ->builder ->get ();
61
+
62
+ if (Config::get ('apihandler.cleanup_relations ' , false )) {
63
+ $ result = $ this ->cleanupRelationsOnModels ($ result );
64
+ }
60
65
} else {
61
- $ result = $ this ->cleanupRelations ($ this ->parser ->builder ->first ());
66
+ $ result = $ this ->parser ->builder ->first ();
67
+
68
+ if (Config::get ('apihandler.cleanup_relations ' , false )) {
69
+ $ result = $ this ->cleanupRelations ($ result );
70
+ }
62
71
}
63
72
64
73
return $ result ;
You can’t perform that action at this time.
0 commit comments