Skip to content

Commit 29c6666

Browse files
committed
fix: use exception instead of response in onBefore callback for duplicate driver check
The previous fix returned response()->error() directly from inside the createRecordFromRequest onBefore callback. The trait checks for a JsonResponse return and short-circuits correctly, but the outer createRecord method then passed the JsonResponse object as $record into the Driver resource serializer (line 245), causing: ErrorException: Undefined property: Illuminate\Http\JsonResponse::$id in DelegatesToResource.php The correct approach is to throw a \Exception from within the callback, which propagates out of createRecordFromRequest and is caught by the existing catch (\Exception $e) block, which then returns response()->error($e->getMessage()) — producing the correct 400 JSON error response to the frontend.
1 parent fc3548f commit 29c6666

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

server/src/Http/Controllers/Internal/v1/DriverController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function (&$request, &$input) {
141141
if ($user) {
142142
$existingDriver = Driver::where(['user_uuid' => $user->uuid, 'company_uuid' => session('company')])->first();
143143
if ($existingDriver) {
144-
return response()->error('This user account already belongs to a driver.');
144+
throw new \Exception('This user account already belongs to a driver.');
145145
}
146146
}
147147

0 commit comments

Comments
 (0)