Problems with ide-helper laravel: Factory not found - php

I am running ide-helper in my Laravel Framework 8.33.1 project. To generate the model facade declarations (command: php artisan ide-helper:models) I am getting this error:
Exception: Class 'Database\Factories\XXXFactory' not found
Could not analyze class App\Models\XXX.
Do I need a factory for each model or why is that?

In your Ide-helper config file, set 'include_factory_builders' to false
config/ide-helper.php
'include_factory_builders' => false,

Seems like this is a known bug with ide-helper 2.9.1, see here:
Github Issue 1188 ide-helper
How I solved it:
I removed
use HasFactory
from all models which do not have an according factory class implemented.

Related

Adjust Seeders integration for Package Development in Laravel 8

I developed a package for an api in laravel.7.x. That api is delivered as an package for laravel. Now I want to upgrade it to laravel 8. Unfortunately I cannot get the seeders to work.
all package Seeders should executed after the
php artisan migrate:fresh --seed
command.
Appearantly the Seeder classes are not found. for Example Target class [PostSeeder] does not exist.
But it does exist, it's even in the same namespace.
Now I'm trying to start in with a DatabaseSeeder and this one IS found. But from there the other Seeders can't be triggered.
Does anyone has an Idea what can be tried or has a hint or code snippet for this problem?
Many thanks in advance.
alright, the issue is solved.
Use the new way of including factories in laravel 8 i.e Models have this new function:
use Acme\YourPackage\Database\Factories\PostFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
protected static function newFactory()
{
return PostFactory::new();
}
and make sure to call it like:
enter $this->call('Acme\YourPackage\Database\Seeders\PostSeeder');
after that make your sure your namespace and class paths are set correctly.

Laravel 5 error Class 'App' not found in

I am currently learning laravel 5 and wanted to implement the repository concept.
as I understand. I should put an ioc.php and the config folder and put my bindings their
Here is my config/ioc.php
<?php
App::bind('QuestionRepository', 'IQuestionRepository');
App::bind('AnswerRepository', 'IAnswerRepository');
I get an error Class 'App' not found in
try prefixing App with \ like \App
For my case in lumen 5.4, undefined 'App' class issue solved by facade definition:
use Illuminate\Support\Facades\App;
In my case, my .env file contained a value with spaces after checking out a new project.
Running php artisan optimize for the first time would throw this error because my Exception handler was trying to use the '\App' global alias for the App facade. Commenting that code showed the real error;
"Dotenv values containing spaces must be surrounded by quotes."

How can I use Cache during application bootstrapping?

I am migrating a Laravel 4.2 application to Laravel 5.1.
During bootstrap, when loading the mail configuration file (config/mail.php), I want to read my SMTP configuration from DB and cache it.
In order to do that I use an Eloquent model class, in which I use the Cache facade's remember() function to get the data I need.
It used to work in 4.2, but after switching to 5.1, I get the following error message:
Call to a member function remember() on a non-object
This happens after I put the following line at the top of the class:
use Illuminate\Support\Facades\Cache;
Without that line I got a Class 'Cache' not found error message.
Any idea what am I missing? Is this even possible in 5.1?
Thanks a lot!

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in dbunit\PHPUnit\Extensions\Database\TestCase.php on line 24

I want to write tests for MySQL Database. When I try to extend the database extension, it gives me the above error in title:
class FixtureTestCase extends PHPUnit_Extensions_Database_TestCase
Note: I have installed PHPUnit globally and I can access it through phpunit in cmd. I have latest PHPUnit 4.5.1.
I also installed Dbunit globally through composer:
composer global require phpunit/dbunit
Any help will be much appreciated. I've used PHP 5.4.
For referring to classes that are located within the global namespace, you can simply prefix them with a backward ( \ ) slash.
Try with this:
class FixtureTestCase extends \PHPUnit_Extensions_Database_TestCase
With the leading backward ( \ ) slash, PHP knows that we are referring to the PHPUnit_Extensions_Database_TestCase class in the global namespace, and located that one.
More info here
Hope this help.
It just might be the version of DBUnit. For example I'm using PHPUnit 4.8 and it works with DBUnit 1.4.
I had the above error when I was using composer with "phpunit/dbunit": ">=1.2" and I ended up with DBUnit 2.0.
Test your DB how? Through an API you created or direct accesses to DB? i would recommend you to write an API to access your DB and then write the tests to the API.
for exemple if you want to insert a user you call your web-server address (localhost:3000) or something you have and then call /users through POST to insert and make the routes to that.
I would suggest using LARAVEL for that.

Call to undefined method Shell::getAssociated()

I got a subj error when I creating some models.
I use the last cake version and windows 7.
So, what the problem is and how can I fix it?
This is probably issue with include_path, check if cake library is included in php.ini's include_path=".;c:/php5/cake"
Okay I solved problem. The problem was because I have database table named 'shells' and when I baked model via 'cake bake' there was generated model 'shells.php' which overrided core class 'Shell'.

Categories