php - Laravel5 Carbon date string not correctly parsing -
i've been struggling issue on 4 hours now. laravel's carbon date thing isn't playing nice bootstrap or something.
i've been trying set mutator articles model
public function setpublishedatattribute($date){ $this->attributes['published_at'] = carbon::createfromformat($date); }
in articles model, i've included use carbon\carbon;
. @ point, have bootstrap date picker:
<div class="form-group"> {!! form::label('published_at', 'publish on:') !!} {!! form::input('date', 'published_at', date('y-m-d'),[ 'class' => 'form-control']) !!} </div>
my error log throws this:
[2015-08-16 22:32:36] production.error: exception 'invalidargumentexception' message 'trailing data' in /users/alexanderkleinhans/misc/laravel_test/laravel/vendor/nesbot/carbon/src/carbon/carbon .php:414
and huge stack trace:
#0 /users/alexanderkleinhans/misc/laravel_test/laravel/app/article.php(17): carbon\carbon::createfromformat('y-m-d', object(carbon\carbon)) #1 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(10577): app\article->setpublishedatattribute(object(carbon\carbon)) #2 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9615): illuminate\database\eloquent\model->setattribute('published_at', object(carbon\carbon)) #3 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9553): illuminate\database\eloquent\model->fill(array) #4 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9665): illuminate\database\eloquent\model->__construct(array) #5 /users/alexanderkleinhans/misc/laravel_test/laravel/app/http/controllers/articlescontroller.php(36): illuminate\database\eloquent\model::create(array) #6 [internal function]: app\http\controllers\articlescontroller->store() #7 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(8490): call_user_func_array(array, array) #8 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(8559): illuminate\routing\controller->callaction('store', array) #9 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(8539): illuminate\routing\controllerdispatcher->call(object(app\http\controllers\articlescontroller), object(illuminate\routing\route), 'store') #10 [internal function]: illuminate\routing\controllerdispatcher->illuminate\routing\{closure}(object(illuminate\http\request)) #11 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9196): call_user_func(object(closure), object(illuminate\http\request)) #12 [internal function]: illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #13 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9178): call_user_func(object(closure), object(illuminate\http\request)) #14 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(8540): illuminate\pipeline\pipeline->then(object(closure)) #15 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(8525): illuminate\routing\controllerdispatcher->callwithinstack(object(app\http\controllers\articlescontroller), object(illuminate\routing\route), object(illuminate\http\request), 'store') #16 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(7500): illuminate\routing\controllerdispatcher->dispatch(object(illuminate\routing\route), object(illuminate\http\request), 'app\\http\\contro...', 'store') #17 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(7471): illuminate\routing\route->runwithcustomdispatcher(object(illuminate\http\request)) #18 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(7124): illuminate\routing\route->run(object(illuminate\http\request)) #19 [internal function]: illuminate\routing\router->illuminate\routing\{closure}(object(illuminate\http\request)) #20 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9196): call_user_func(object(closure), object(illuminate\http\request)) #21 [internal function]: illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #22 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9178): call_user_func(object(closure), object(illuminate\http\request)) #23 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(7125): illuminate\pipeline\pipeline->then(object(closure)) #24 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(7113): illuminate\routing\router->runroutewithinstack(object(illuminate\routing\route), object(illuminate\http\request)) #25 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(7098): illuminate\routing\router->dispatchtoroute(object(illuminate\http\request)) #26 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(2088): illuminate\routing\router->dispatch(object(illuminate\http\request)) #27 [internal function]: illuminate\foundation\http\kernel->illuminate\foundation\http\{closure}(object(illuminate\http\request)) #28 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9196): call_user_func(object(closure), object(illuminate\http\request)) #29 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(2708): illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #30 [internal function]: illuminate\foundation\http\middleware\verifycsrftoken->handle(object(illuminate\http\request), object(closure)) #31 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9188): call_user_func_array(array, array) #32 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(12456): illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #33 [internal function]: illuminate\view\middleware\shareerrorsfromsession->handle(object(illuminate\http\request), object(closure)) #34 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9188): call_user_func_array(array, array) #35 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(11104): illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #36 [internal function]: illuminate\session\middleware\startsession->handle(object(illuminate\http\request), object(closure)) #37 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9188): call_user_func_array(array, array) #38 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(12193): illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #39 [internal function]: illuminate\cookie\middleware\addqueuedcookiestoresponse->handle(object(illuminate\http\request), object(closure)) #40 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9188): call_user_func_array(array, array) #41 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(12132): illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #42 [internal function]: illuminate\cookie\middleware\encryptcookies->handle(object(illuminate\http\request), object(closure)) #43 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9188): call_user_func_array(array, array) #44 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(2758): illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #45 [internal function]: illuminate\foundation\http\middleware\checkformaintenancemode->handle(object(illuminate\http\request), object(closure)) #46 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9188): call_user_func_array(array, array) #47 [internal function]: illuminate\pipeline\pipeline->illuminate\pipeline\{closure}(object(illuminate\http\request)) #48 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(9178): call_user_func(object(closure), object(illuminate\http\request)) #49 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(2035): illuminate\pipeline\pipeline->then(object(closure)) #50 /users/alexanderkleinhans/misc/laravel_test/laravel/bootstrap/cache/compiled.php(2018): illuminate\foundation\http\kernel->sendrequestthroughrouter(object(illuminate\http\request)) #51 /users/alexanderkleinhans/misc/laravel_test/laravel/public/index.php(60): illuminate\foundation\http\kernel->handle(object(illuminate\http\request)) #52 /users/alexanderkleinhans/misc/laravel_test/laravel/server.php(21): require_once('/users/alexande...') #53 {main}
the funny thing is that:
public function setpublishedatattribute($date){ $this->attributes['published_at'] = carbon::parse($date); }
will work, completly useless. record date correctly, it's current date. don't recall using carbon::now()
, date must coming boostrap? when set bootstraps date picker else, nothing registers.
i've combed through thing , wasted enough time on it. in advance.
edit. have in face discovered carbon , laravel not issue , in fact, parse($date)
, despite being little more overhead createfromformat
working. kicks, tried
public function setpublishedatattribute($date){ $this->attributes['published_at'] = carbon::parse($date); $this->attributes['body'] = $date; }
just see was. bootstrap in fact issue.
the reason you're getting error you're setting published_at incorrectly. carbon::createfromformat() requires second argument string, yet you're passing carbon object.
that's can see in stack trace:
#0 /users/alexanderkleinhans/misc/laravel_test/laravel/app/article.php(17): carbon\carbon::createfromformat('y-m-d', object(carbon\carbon))
Comments
Post a Comment