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.
Related
I have recently started using laravel for work and I boumped into many issues I cannot stil solve.
I have looked over many many topics and already anwered questions but none of those have helped me with my issue
So, I get this error trying to do 'php artisan serve'
"Non-static method Illuminate\Cache\RateLimiter::for() should not be called statically"
So I went up looking at the code, this is the RateLimiter.php code that gives me the error
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
the error is at the 2nd line of this code, in the RateLimiter:: etc
I get those errors in the CMD
app/Providers/RouteServiceProvider.php:59
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Non-static method Illuminate\Cache\RateLimiter::for() should not be called statically", "myPathToTheProject/app/Providers/RouteServiceProvider.php", [])
app/Providers/RouteServiceProvider.php:38
App\Providers\RouteServiceProvider::configureRateLimiting()
the function is called like this
$this->configureRateLimiting();
hoping you can help me, I will give more infos if are needed
I found out the problem. You need to import the facade, and when you auto-import, it tends to get the wrong package.
Look at the imports. If you find:
use Illuminate\Cache\RateLimiter;
You should replace with
use Illuminate\Support\Facades\RateLimiter;
Worked for me!
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'm trying to create a program which generates event dates for the whole year. The program works if the user select few events but if the user select 100+ events and assigned them every week it reaches the Maximum execution time error.
In order to fix this, my idea is to run the program in the background.
I'm using Laravel 5.4, running the script below will call the function
$process = new Process('php -f '.$path.' generate_evnt_prepared ' . $content['evntid']);
$process->run();
Function Script
namespace App\Library\shellexec;
use App\Model\V1\EvntPlanDtl;
use App\Model\V1\EvntPlanDtlPrePo;
use Carbon\Carbon;
class RoutePlan {
//put your code here
public function process($method = null, $param = 0)
{
$this->$method($param);
}
I'm pretty sure that the function is called as I'm getting an error in error_logs that the Models are not found
PHP Fatal error: Class 'App\Model\V1\EvntPlanDtl' not found in C:\xampp\htdocs\rdmsoffice\app\Library\shellexec\EventPlan.php on line 30
PHP Stack trace:
PHP 1. {main}() C:\xampp\htdocs\rdmsoffice\app\Library\shellexec\EventPlan.php:0
PHP 2. App\Library\shellexec\EventPlan->process() C:\xampp\htdocs\rdmsoffice\app\Library\shellexec\EventPlan.php:88
PHP 3. App\Library\shellexec\EventPlan->generate_evnt_prepared ()
Anyone knows how to fix this? I'm open to suggestions if this is the wrong way.
Big thanks!
Sounds like a more scalable way is to create a "chunked" version and fire them into a queue for processing. For example, based off some assumptions about the example you provided, I might suggest one firing one queued message for each Event the user selects.
That adds some overhead to manage, but honestly I've always found it's more effective to take some of that cost up front and do it right, rather than finding workarounds like increasing settings or (shudder) shelling out to sub processes.
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
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.