laravel-oci8
laravel-oci8 copied to clipboard
Related records and accessors are not in the 'visible' list, can't automatically serialize model with relations to JSON
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
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.
Did you extend OracleEloquent or just the default Laravel Model?
Yes,
use Yajra\Oci8\Eloquent\OracleEloquent as Model;
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.