Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$cast decimal cause ErrorException Undefined offset: 1 #2146

Closed
wohcnosae opened this issue Dec 9, 2020 · 1 comment
Closed

$cast decimal cause ErrorException Undefined offset: 1 #2146

wohcnosae opened this issue Dec 9, 2020 · 1 comment
Labels
Needs investigation Need investigation about bugs described in issue

Comments

@wohcnosae
Copy link

  • Laravel-mongodb Version: 3.8
  • PHP Version: 7.4
  • Database Driver & Version: 1.9.0

Description:

after add $cast 'credit_balance' => 'decimal' on User.php
when print $user->credit_balance will get this exception

Expected behaviour

ErrorException Undefined offset: 1
\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php:557
return $this->asDecimal($value, explode(':', $this->getCasts()[$key], 2)[1]);

Actual behaviour

Tell us what happens instead

Logs: [2020-12-09 15:03:13] local.ERROR: Undefined offset: 1 {"userId":"5fd04c162d7f0000870074a4","exception":"[object] (ErrorException(code: 0): Undefined offset: 1 at D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php:557) [stacktrace] #0 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(557): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined offse...', 'D:\\\\COMPANY\\\\UG_S...', 557, Array) #1 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(1602): Illuminate\\Database\\Eloquent\\Model->castAttribute('credit_balance', Object(MongoDB\\BSON\\Decimal128)) #2 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(407): Illuminate\\Database\\Eloquent\\Model->transformModelValue('credit_balance', Object(MongoDB\\BSON\\Decimal128)) #3 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Concerns\\HasAttributes.php(386): Illuminate\\Database\\Eloquent\\Model->getAttributeValue('credit_balance') #4 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\jenssegers\\mongodb\\src\\Jenssegers\\Mongodb\\Eloquent\\Model.php(157): Illuminate\\Database\\Eloquent\\Model->getAttribute('credit_balance') #5 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Eloquent\\Model.php(1786): Jenssegers\\Mongodb\\Eloquent\\Model->getAttribute('credit_balance') #6 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\app\\Http\\Controllers\\Dashboard\\DashboardController.php(53): Illuminate\\Database\\Eloquent\\Model->__get('credit_balance') #7 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php(54): App\\Http\\Controllers\\Dashboard\\DashboardController->total_sma_count() #8 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('total_sma_count', Array) #9 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(254): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\Dashboard\\DashboardController), 'total_sma_count') #10 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(197): Illuminate\\Routing\\Route->runController() #11 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(692): Illuminate\\Routing\\Route->run() #12 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(128): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request)) #13 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\app\\Http\\Middleware\\Localization.php(22): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #14 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): App\\Http\\Middleware\\Localization->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #15 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Middleware\\SubstituteBindings.php(41): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #16 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #17 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php(77): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #18 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #19 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #20 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #21 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(121): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #22 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(63): Illuminate\\Session\\Middleware\\StartSession->handleStatefulRequest(Object(Illuminate\\Http\\Request), Object(Illuminate\\Session\\Store), Object(Closure)) #23 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #24 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #25 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #26 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(67): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #27 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #28 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #29 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(694): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #30 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(669): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request)) #31 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(635): Illuminate\\Routing\\Router->runRoute(Object(Illuminate\\Http\\Request), Object(Illuminate\\Routing\\Route)) #32 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(624): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request)) #33 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(166): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request)) #34 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(128): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request)) #35 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #36 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #37 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #38 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #39 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #40 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #41 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance.php(87): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #42 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #43 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\fruitcake\\laravel-cors\\src\\HandleCors.php(37): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #44 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Fruitcake\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #45 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\fideloper\\proxy\\src\\TrustProxies.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #46 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Fideloper\\Proxy\\TrustProxies->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #47 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Http\\Middleware\\TrustHosts.php(48): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #48 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(167): Illuminate\\Http\\Middleware\\TrustHosts->handle(Object(Illuminate\\Http\\Request), Object(Closure)) #49 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request)) #50 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(141): Illuminate\\Pipeline\\Pipeline->then(Object(Closure)) #51 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request)) #52 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\public\\index.php(52): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request)) #53 D:\\COMPANY\\UG_SYSTEM PROJECT\\v2ugadmin\\server.php(21): require_once('D:\\\\COMPANY\\\\UG_S...') #54 {main} "}
@Smolevich Smolevich added the Needs investigation Need investigation about bugs described in issue label Dec 14, 2020
@hans-thomas
Copy link
Contributor

It's because you must determine the numbers after the decimal point.

protected $casts = [
    'age' => 'decimal:5'
];

@GromNaN GromNaN closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs investigation Need investigation about bugs described in issue
Projects
None yet
Development

No branches or pull requests

4 participants