Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related records and accessors are not in the 'visible' list, can't automatically serialize model with relations to JSON #708

Closed
m0stwan1ed opened this issue Apr 11, 2022 · 5 comments
Labels

Comments

@m0stwan1ed
Copy link

Summary of problem or feature request

Method ->with(), which added relation to model for future export toJson() or toArray() does not add field to 'visible list'.
Adding field via ->makeVisible([]) manually fixes problem;

Code snippet of problem

App\Models\OracleModel::with(['relation'])->first()->toJson(); // Returns model **without 'relation'**
App\Models\OracleModel::with(['relation'])->first()->getVisible(); // Returns all fields **without 'relation'**, but it normally works with other DB drivers

App\Models\OracleModel::with(['relation'])->first()->makeVisible(['relation'])->toJson(); // Returns JSON **with** all related records
App\Models\OracleModel::with(['relation'])->first()->makeVisible(['relation'])->getVisible(); // Returns all fields **with** 'relation'

System details

  • Laravel Homestead (dev server)
  • PHP 7.4
  • Laravel Version 8.83.5
  • Laravel-OCI8 Version 8.6.1
@m0stwan1ed m0stwan1ed changed the title Related records are not in the 'visible' list, can' automatically serialize model with relations to JSON Related records are not in the 'visible' list, can't automatically serialize model with relations to JSON Apr 12, 2022
@m0stwan1ed
Copy link
Author

m0stwan1ed commented Apr 12, 2022

This bug applies to Eloquent Accessors - it won't be visible unless it won't be manually added to "visible" list, even if it has been added to $appends array in model.

@m0stwan1ed m0stwan1ed changed the title Related records are not in the 'visible' list, can't automatically serialize model with relations to JSON Related records and accessors are not in the 'visible' list, can't automatically serialize model with relations to JSON Apr 12, 2022
@yajra
Copy link
Owner

yajra commented May 21, 2022

Did you extend OracleEloquent or just the default Laravel Model?

@m0stwan1ed
Copy link
Author

Yes,
use Yajra\Oci8\Eloquent\OracleEloquent as Model;

@github-actions
Copy link

github-actions bot commented Oct 7, 2022

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Oct 7, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants