laravel-oci8 icon indicating copy to clipboard operation
laravel-oci8 copied to clipboard

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

Open m0stwan1ed opened this issue 3 years ago • 3 comments

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 avatar Apr 11 '22 16:04 m0stwan1ed

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 avatar Apr 12 '22 11:04 m0stwan1ed

Did you extend OracleEloquent or just the default Laravel Model?

yajra avatar May 21 '22 10:05 yajra

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

m0stwan1ed avatar May 21 '22 11:05 m0stwan1ed

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

github-actions[bot] avatar Oct 07 '22 03:10 github-actions[bot]

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

github-actions[bot] avatar Oct 14 '22 04:10 github-actions[bot]