I have my installation of laravel 4 under HHVM, and i set up as a accessory on my eloquent an converter date from SQL date to human.
doing something like that:
public function getDateSpanAttribute($value)
{
return $value = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s',$this->created_at)->diffForHumans();
}
This method work well under php5, no error just work. On HHVM this accessory throw me an exception saying,
{"error":{"type":"InvalidArgumentException","message":"Unknown setter
'_date_time'","file":"/var/www/mynextmatch/vendor/nesbot/carbon/src/Carbon/Carbon.php","line":542}}
I saw the source of Carbon on that row and it is the magic method __get() to give this problem but i cannot figure out why it happening.
I will appreciate same help. Thanks
Not sure about the error on HHVM but one thing is for sure that an accessor method doesn't contain any argument, it should be (Manual):
public function getDateSpanAttribute()
{
return \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $this->created_at)->diffForHumans();
}
You just need to return the property not setting anything, if you want to set anything then it would be a setter/mutator method which acepts a value as argument.
I am having the same issue but think mine is tied to creating a session creation after logging in (
InvalidArgumentException Unknown setter '_date_time'). Mine is installed on HHVM 3.1 running on Ubuntu 14.04. I have the same set up using Ubuntu 12.04 and am not having this issue.
10. InvalidArgumentException
…/vendor/nesbot/carbon/src/Carbon/Carbon.php542
9. Carbon\Carbon __set
<#unknown>0
8. DateTime __sleep
<#unknown>0
7. serialize
…/vendor/laravel/framework/src/Illuminate/Session/Store.php222
6. Illuminate\Session\Store save
…/vendor/laravel/framework/src/Illuminate/Session/Middleware.php126
Related
I am seeing a lot of issues with the upgrade path from Laravel 7 to 8, but I encounter a different problem for which I cannot find an answer.
It is this one
Seeding: Database\Seeders\UsersTableSeeder
Error
Call to undefined method Database\Factories\UserFactory::new()
at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factories/Factory.php:737
733▕ public static function factoryForModel(string $modelName)
734▕ {
735▕ $factory = static::resolveFactoryName($modelName);
736▕
➜ 737▕ return $factory::new();
738▕ }
739▕
740▕ /**
741▕ * Specify the callback that should be invoked to guess factory names based on dynamic relationship names.
+1 vendor frames
2 database/seeders/UsersTableSeeder.php:17
App\User::factory()
+7 vendor frames
10 database/seeders/DatabaseSeeder.php:15
Illuminate\Database\Seeder::call()
You have probably read in the Upgrade Guide from 7 to 8 that Factories and Seeders are changed in Laravel 8.
If you don't have many Factories and Seeders you can write them from scratch.
I extended the wrong Factory class.
The one I was using was Faker\Factory but instead I must use Illuminate\Database\Eloquent\Factories\Factory.
It was probably because I used the 'import class' function of PHPStorm too quickly.
I am using a 3rd party library that provides a constructor which expects an instance of Psr\Log\LoggerInterface. The constructor in that code looks like:
public function __construct(
$configuration = null,
\Psr\Log\LoggerInterface $logger = null
)
{
In my Laravel 5.5 application I had written a service provider to set up that library for me, and I got access to a LoggerInterface for it by using Laravel's Log::getMonolog():
$connection_manager = ConnectionManager::factory(
config('the_lib_config'),
\Log::getMonolog()
);
With the changes to logging that took place in Laravel 5.6, however, the method getMonolog has gone away. I understand why this method isn't there now, but I'm wondering what the prescribed method is to get what this class needs so that it can log in context of the Laravel app (with all the new Laravel logging goodness).
My Google-Fu got stronger throughout the day, and I found the answer I was looking for in a response by #ermyril at https://laracasts.com/discuss/channels/laravel/getting-laravels-logger-instance?reply=530098
The answer is:
\Log::getLogger();
I get this error on user registration. I have searched for this problem a lot and still couldn't solve the problem on my side. In laravel 5.8 upgrade, it's written that function fire() is changed to dispatch(), but I can't find any fire() function in any file of my app, so I can see what's happening.
Would appreciate any help. Thanks.
From: https://laravel.com/docs/5.8/events#dispatching-events
Instead of:
Event::fire(new \App\Events\NewUserSignup($new_user));
Do instead:
event(new \App\Events\NewUserSignup($new_user));
The fire method (which was deprecated in Laravel 5.4) of the Illuminate\Events\Dispatcher class has been removed(https://github.com/laravel/framework/pull/26392). You should use the dispatch method instead.
Instead of:
Event::dispatch('customer.created', $customer);
Do this:
Event::dispatch('customer.created', $customer);
OR:
event('customer.created', $customer);
I tried to use the Laravel carbon isoFormat method. I received the error Method isoFormat does not exist. My Laravel implementation is 5.7. I tried composer update, and verified that it updated nesbot/carbon.
I copied and pasted code from Mr. Nesbot's manual to see if his code would work.
$mutable = Carbon::now();
var_dump($mutable->isoFormat('dddd D'));
Mr. Nesbot's code produces the same error.
How do I resolve this error, please?
Try the following:
$carbon = new Carbon('now');
$formatted = $carbon->toIso8601String();
var_dump($formatted);
According to the Laravel 4 Documentation on queued Events, I tried to register an event flusher this way:
Event::flusher('foo.bar', function($data)
{
Mail::send(array('emails.notification', 'emails.notification_text'), array('content' => $data), function($message)
{
$message
->to('email#example.com', 'My Name')
->bcc('test#example.com')
->subject('Message from Listener');
});
});
But I am getting the following error upon loading of the script:
Call to undefined method Illuminate\Events\Dispatcher::flusher()
I also couldn't find this method in the source codes of L4. But when I change this from Event::flusher() to Event::listen(), everything works as expected.
So my guess is, that the documentation isn't up to date and the Event::flusher() method has been dropped, since Event::listen() does the same work. Or are there any differences between those two methods and I have an error in my code?
You may need to update your libraries using:
$ composer update
If that doesn't work, let us know what your composer.json file looks like - you might be using a beta version if the framework. It was updated very often before the first stable release.