Description
-Laravel-mongodb Version: 5.1.0
-PHP Version: 8.3.0
-Database Driver & Version:
Description:
We store our primary keys in the database as _id, and throughout our project, we use $model->_id without issues. However, when using the following pattern:
$get = Model::all();
return response()->json(['data' => $get]);
The _id field causes problems, and APIs fail because _id cannot be directly handled in this context. To work around this issue, we have to perform a mapping, which is tedious.
We request a more permanent solution for this. Specifically, having the ability to define the primary key dynamically in the model (e.g., $primaryKey = '_id' or $primaryKey = 'id'). This would allow developers to continue using _id seamlessly without rewriting or remapping the data structure.
Steps to reproduce:
Set up a model with _id as the primary key in the database.
Query all records using Model::all().
Return the result as JSON using response()->json().
Expected behavior:
The _id field should be included and correctly handled when returning the data as JSON, without requiring additional mapping.
Actual behavior:
The _id field is not properly managed, and APIs fail unless we manually map it to id.