我一直在打开和关闭这个问题大约一个月了。我的开发环境是带有IIS的Windows,我的生产是在AWS Elastic Beanstalk上。除了获取带有ajax请求的模型之外,一切都是AWS工作。我在下面收到此错误。
InvalidArgumentException:缺少数据 /var/app/current/vendor/nesbot/carbon/src/Carbon/Carbon.php:582
我的Windows Dev环境中没有发生这种情况。我从5.3升级到Laravel 5.4,这个问题仍然存在。
我可以看到Laravel正在尝试更新时间戳,这是堆栈跟踪中的最后一行。
/var/app/current/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(688):Carbon \ Carbon :: createFromFormat(' Ymd H:i:s .000',' 2017-02-05 20:15:15')
你绝对可以看到数据丢失,这可以解释错误,但我的代码并没有直接调用它,我无法找到改变它的位置。
请注意,这只发生在Ajax调用中。我可以在没有AJAX的情况下创建,更新和删除数据库记录,并且工作正常。这是我的JavaScript代码片段
$.ajax({
type: "PUT",
url: '/config/vlans/' + device_id,
success: function (data) {
// Do Stuff
},
error: function (data) {
}
});
另请注意,当模型未返回任何记录时,AJAX调用成功。
请帮忙。
编辑 - 堆栈跟踪和控制器代码
AJAX响应文本
InvalidArgumentException in Carbon.php line 582:
Data missing
in Carbon.php line 582
?
at Carbon::createFromFormat('Y-m-d H:i:s.000', '2017-02-18 15:39:46') in Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 561
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 520
at Router->dispatchToRoute(object(Request)) in Router.php line 498
at Router->dispatch(object(Request)) in Kernel.php line 174
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 53
laravel.log条目
[2017-02-20 00:46:03] production.ERROR: InvalidArgumentException: Data missing in /var/app/current/vendor/nesbot/carbon/src/Carbon/Carbon.php:582
Stack trace:
#0 /var/app/current/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(709): Carbon\Carbon::createFromFormat('Y-m-d H:i:s.000', '2017-02-18 15:3...')
#1 /var/app/current/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(122): Illuminate\Database\Eloquent\Model->asDateTime('2017-02-18 15:3...')
#2 /var/app/current/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(84): Illuminate\Database\Eloquent\Model->addDateAttributesToArray(Array)
#3 /var/app/current/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(884): Illuminate\Database\Eloquent\Model->attributesToArray()
#4 /var/app/current/vendor/laravel/framework/src/Illuminate/Support/Collection.php(1313): Illuminate\Database\Eloquent\Model->toArray()
#5 [internal function]: Illuminate\Support\Collection->Illuminate\Support\{closure}(Object(App\DeviceInterface))
#6 /var/app/current/vendor/laravel/framework/src/Illuminate/Support/Collection.php(1314): array_map(Object(Closure), Array)
#7 /var/app/current/vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php(61): Illuminate\Support\Collection->toArray()
#8 /var/app/current/vendor/symfony/http-foundation/JsonResponse.php(50): Illuminate\Http\JsonResponse->setData(Object(Illuminate\Database\Eloquent\Collection))
#9 /var/app/current/vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php(27): Symfony\Component\HttpFoundation\JsonResponse->__construct(Object(Illuminate\Database\Eloquent\Collection), 200, Array)
#10 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/ResponseFactory.php(83): Illuminate\Http\JsonResponse->__construct(Object(Illuminate\Database\Eloquent\Collection), 200, Array, 0)
#11 /var/app/current/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Illuminate\Routing\ResponseFactory->json(Object(Illuminate\Database\Eloquent\Collection))
#12 /var/app/current/app/Http/Controllers/ConfigController.php(1145): Illuminate\Support\Facades\Facade::__callStatic('json', Array)
#13 [internal function]: App\Http\Controllers\ConfigController->get('device_interfac...', '1')
#14 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(55): call_user_func_array(Array, Array)
#15 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('get', Array)
#16 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\ConfigController), 'get')
#17 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Route.php(160): Illuminate\Routing\Route->runController()
#18 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(559): Illuminate\Routing\Route->run()
#19 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#20 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#21 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#22 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 /var/app/current/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#24 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Auth\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure))
#25 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(65): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 /var/app/current/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#31 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 /var/app/current/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#33 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /var/app/current/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#36 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#37 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 /var/app/current/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#39 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#40 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#41 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#42 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(561): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#43 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(520): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#44 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Router.php(498): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#45 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(174): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#46 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#47 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#48 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#49 /var/app/current/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#50 /var/app/current/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#51 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(149): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#52 /var/app/current/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#53 /var/app/current/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#54 {main}
路线
Route::put('/config/{object}/{id}', 'ConfigController@get');
控制器代码
public function get($object, $id)
{
if ($object == "vlans")
{
$vlan = Vlan::where('device_id',$id)
->where('nat', true)
->get();
return Response::json($vlan);
}
if ($object == "device_interfaces")
{
$device_interfaces = DeviceInterface::where('device_id', $id)
->orderBy('link_speed', 'int_num')
->get();
return Response::json($device_interfaces);
}
}