hey there, is there's a way to implement mongodb "DBrefs" with this library? thanks a lot :)
i have the same question.
Use
use MongoDB\BSON\ObjectId;
After all you, need to create DBRef struct, like mongodb doc
public function store(Request $request)
{
$data = $request->all();
if($data['id_role']){
$role = [
'$ref' => 'role',
'$id' => new ObjectId($dados['id_role'])
];
unset($data['id_role']);
$data['role'] = $role;
}
return User::create($data);
}
Example of my controller, but you will need to load the DBRefs manually on show.
public function show($id)
{
$user = User::find($id);
if($user){
$user->role = Role::find($user->role['$id']);
return $user;
}
return response('{"message":"NOT FOUND"}', 404);
}
Most helpful comment
Use
use MongoDB\BSON\ObjectId;After all you, need to create DBRef struct, like mongodb doc
Example of my controller, but you will need to load the DBRefs manually on show.