Fzaninotto Faker Install package - php

Can you help me with this error in laravel? I ran php artisan db:seed --class=UserTableSeeder and got:
PHP Fatal error:
Class 'Faker\Factory' not found in /Users/I/Laravel/authapp/app/database/seeds
/UserTableSeeder.php on line 7
{
"error":{
"type":"Symfony\\Component\\Debug\\Exception \\FatalErrorException",
"message":"Class 'Faker\\Factory' not found",
"file":"\/Users /I\/Laravel\/authapp\/app\/database\/seeds\/UserTableSeeder.php",
"line":7
}
}
My UserTableSeeder.php
<?php
class UserTableSeeder extends Seeder
{
public function run()
{
$faker = Faker\Factory::create();
User::truncate();
foreach(range(1,30) as $index)
{
User::create([
'username' => str_replace('.', '_', $faker->unique()->userName),
'email' => $faker->email,
'password' => 'password',
]);
}
}
}
My composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*#dev"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable",
"require-dev": {
"fzaninotto/faker": "1.3.*#dev"
},
}
After adding the comma, I still get the same error and If I try to include it using autoload from github it also does not work. Where could I look for the error?
I still get the same error. I am scared that it is not loading the Fzniotto Faker Package. What can I do? If I try to include the package by downlaoding it, I get
PHP Warning: Uncaught exception 'ErrorException' with message 'require_once(../../../vendor/Faker/autoload.php): failed to open stream: No such file or directory' in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php:6
Stack trace:
#0 /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php(6): Illuminate\Exception\Handler->handleError(2, 'require_once(.....', '/Users/stefanie...', 6, Array)
#1 /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php(6): UserTableSeeder::run()
#2 /Users/stefanieness/Laravel/authapp/vendor/laravel/framework/src/Illuminate/Database/Console/SeedCommand.php(57): UserTableSeeder->run()
#3 /Users/stefanieness/Laravel/authapp/vendor/laravel/framework/src/Illuminate/Console/Command.php(112): Illuminate\Database\Console\SeedCommand->fire()
#4 /Users/stefanieness/Laravel/authapp/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), O in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php on line 6
PHP Fatal error: UserTableSeeder::run(): Failed opening required '../../../vendor/Faker/autoload.php' (include_path='/Users/stefanieness/Laravel/authapp/vendor/phpseclib/phpseclib/phpseclib:.:') in /Users/stefanieness/Laravel/authapp/app/database/seeds/UserTableSeeder.php on line 6
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"UserTableSeeder::run(): Failed opening required '..\/..\/..\/vendor\/Faker\/autoload.php' (include_path='\/Users\/stefanieness\/Laravel\/authapp\/vendor\/phpseclib\/phpseclib\/phpseclib:.:')","file":"\/Users\/stefanieness\/Laravel\/authapp\/app\/database\/seeds\/UserTableSeeder.php","line":6}}SEICCN-3:authapp stefanieness$

Yup, you forgot a comma
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*#dev"
},
then run composer update

I still get the same error. I am scared that it is not loading the Fzniotto Faker Package. What can I do?
In your shell, try running php artisan dump-autoload.
Run composer update, you are however missing a comma in your composer.json;
"require": {
"laravel/framework": "4.2.*"
"fzaninotto/faker": "1.3.*#dev"
}
Should be;
"require": {
"laravel/framework": "4.2.*",
"fzaninotto/faker": "1.3.*#dev"
}
If you already have the dependency and copied the code wrong try running composer dump-autoload.

However, I now no longer get an error, but I also do not get any users in my table. It seems to be simply not working, eg. the table is not created and filled with lorem ipsum users. What can I do?
Have you created your users table?
If not you need to;
Run php artisan migrate:make create_users_table.
In your app/database/migrations folder you will find your new migration file.
Build your migration (http://laravel.com/docs/4.2/schema).
Run php artisan migrate.
Run php artisan db:seed.

Related

Method ReflectionParameter::getClass() is deprecated, even after downgrading php version to 7.4 [duplicate]

I am getting this error:
PS C:\Users\User\Desktop\jk> php artisan serve
PHP Fatal error: Uncaught ErrorException: Method ReflectionParameter::getClass() is deprecated in C:\Users\User\Desktop\jk\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
Stack trace:
Composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.4|^8.0",
"laravel/framework": "5.4.*",
"laravelcollective/html": "^5.3.0",
"guzzlehttp/guzzle": "^6.3",
"doctrine/dbal": "^2.9"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "^9.3",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"platform": {
"php": "8.0.1"
}
}
}
Container.php Here some part of code
protected function resolveClass(ReflectionParameter $parameter)
{
try {
return $this->make($parameter->getClass()->name);
}
// If we can not resolve the class instance, we will check to see if the value
// is optional, and if it is we will return the optional parameter value as
// the value of the dependency, similarly to how we do this with scalars.
catch (BindingResolutionException $e) {
if ($parameter->isOptional()) {
return $parameter->getDefaultValue();
}
throw $e;
}
}
Method ReflectionParameter::getClass() is deprecated .i think is getclass method is deprecated in version 8.0.1nstead of this i trying to using ReflectionParameter::getType()like link but not working .and also members suggest this
Laravel app stopped working after upgrading to php 8 i tried this also but not working
because ReflectionParameter::getClass() is deprecated in php 8 .
solution go to
vendor\laravel\framework\src\Illuminate\Container\Container.php
and go to
protected function resolvePrimitive(ReflectionParameter $parameter)
and replace
$parameter->getClass()** with **$parameter->getType()->getName() .
Laravel 5.4 seems to have incorrect platform requirements. Specifically that it requires PHP version >= 5.6 however it has code that will not work in PHP 8. Since 5.4 is end of life I would not expect any official code changes to make it work for PHP 8 so you would either need to fork and maintain your own Laravel 5.4 branch that solves these problems or upgrade your Laravel version to one that supports PHP 8.
The first Laravel version that supports PHP 8 is Laravel 6
You can replace it with getType(), which the documentation suggest. You have to create your own ReflectionClass, from the ReflectionType. This should do the trick.
$reflectionClass = new ReflectionClass($reflectionParam->getType()->getName());
I have this sandbox, that helped me assure it was working as intended.
You might need to update your global composer.json with:
composer global update
I had some annoying issue so I hade to run:
composer global update --ignore-platform-reqs

Fatal Error Laravel: Uncaught ReflectionException when i view my Site

I have the following error when i view my site.
My Error:
Fatal error: Uncaught ReflectionException: Class log does not exist in
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php:741> Stack trace: #0
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(741):
ReflectionClass->__construct('log') #1
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(631):
Illuminate\Container\Container->build('log', Array) #2
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674):
Illuminate\Container\Container->make('log', Array) #3
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(842):
Illuminate\Foundation\Application->make('log') #4
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(805):
Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) > #5 /home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php(774):
Il in
/home/vagrant/Code/in10km/vendor/laravel/framework/src/Illuminate/Container/Container.php
on line 741
My Composer.json file is like this
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"doctrine/dbal": "v2.4.2",
"swiftmailer/swiftmailer": "^5.4",
"guzzlehttp/guzzle": "~5.3|~6.0",
"chrisbjr/api-guard": "^2.3",
"serverfireteam/panel": "1.3.*",
"laravel/socialite": "^2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"files": [
"app/Http/helpers.php",
"app/Support/helpers.php"
],
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Anyone help me how to get rid of this error and view my site successfully.
Delete all files in bootstrap/cache/ then run:
composer dump-autoload -o
I had a similar issue. I found that to really dig down into the issue, you need to modify the Illuminate/Container/Container.php file, as suggested here at the third from the top.
<?php
namespace {
use Monolog\Logger as Monolog;
class log extends Illuminate\Log\Writer {
function __construct()
{
$this->monolog = new Monolog("local");
}
}
}
namespace Illuminate\Container {
use Closure;
use ArrayAccess;
use ReflectionClass;
use ReflectionMethod;
use ReflectionFunction;
use ReflectionParameter;
use InvalidArgumentException;
use Illuminate\Contracts\Container\Container as ContainerContract;
use Illuminate\Contracts\Container\BindingResolutionException as BindingResolutionContractException;
class Container implements ArrayAccess, ContainerContract
{
Modify it as the code suggests, and add an additional closing bracket to the bottom. This will allow it to display the error that it otherwise has been unable to display and thus be able to fix your problem!
Delete vendor file and then run composer update
I found the solution, in my routes i don't called exactly the name of the Controller
Example:
Route::get('/endpoint', 'Namebadcontroller#function');
// Correct name of route
Route::get('/endpoint', 'NameBadController#function');
And run the follow commands:
composer dump-autoload -o
php artisan clear-compiled
php artisan optimize
The issue might originate from a package that is not (yet) downloaded in your vendor folder (with all installed vendor packages)
In that case composer dump-autoload -o does not fix your issue.
Check you composer.json and composer.lock.
I added main into my branch from a GIT repo.
composer.json and composer.lock did not match!
The resolution was to recover composer.json and composer.lock from main and readded all changes from my branch manually.
Just to be sure I also removed my vendor folder.
Running composer install (re)installed all packages stored in composer.lock and added all (newer) not yet installed.
Notice that running composer update might fix the issue, but alse updates packages that perhaps may not be updated.
Try the command composer dump-autoload -o.
I used it to overcome the problem: 'Uncaught ReflectionException'.
Good luck!

Fatal error: Class ... not found in ... /ProviderRepository.php on line 146

This sounds like a trivial mistake, but I've been unable to find the solution for hours.
I tried to use https://github.com/michaelbonds/laravel-db2 in my Laravel project, and I added it using composer.
Here's my composer.json.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"michaelb/laravel-db2": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
Here's the error:
PHP Fatal error: Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found in /var/www/html/mysjsu/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
and
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'MichaelB\Database\DB2\DB2ServiceProvider' not found
I found a similar question before on StackOverflow, and somebody suggested that the order matters. So, here's what I did in the following order:
add "michaelb/laravel-db2": "~2.0" to composer.json
run php ../composer.phar update
add MichaelB\Database\DB2\DB2ServiceProvider::class to the providers arary in config/app.php
run php artisan migrate
Any idea on what might've been the problem?
This package is a fork of cooperl/laravel-db2. The documentation is inaccurate.
He changed the namespace to MichaelB but never tagged this as a stable version, so when you composer require his ~2.0, packagist gives you an older version with the wrong namespace.
So when you run composer update, it runs some post-cmd scripts such as php artisan optimize which tries to pull from the config file but fails because that class doesn't exist.
Here's how to fix it:
Change composer.json to this version:
"michaelb/laravel-db2": "dev-master"
Run composer update --no-scripts
Then you should be good.

PHP Fatal error when trying to install Laravel 5 with Composer

I'm trying to run composer to install Laravel 5.0.14, and am also trying to test this code out in Jenkins using the Jenkins php-template.
Whenever I run composer update, I get the following error:
Error Output: PHP Fatal error: Call to undefined method
Illuminate\Foundation\Application::redirectIfTrailingSlash()
in /var/lib/jenkins/jobs/Demo/workspace/bootstrap/start.php on line 16
If I remove the offending line in start.php, I obtain the following error when attempting to run composer update:
Error Output: PHP Catchable fatal error:
Argument 1 passed to Illuminate\Foundation\Application::detectEnvironment()
must be an instance of Closure, array diven, called in
/var/lib/jenkins/jobs/Demo/workspace/bootstrap/start.php on line 32
and defined in
/var/lib/jenkins/jobs/Demo/workspace/vendor/laravel/framework/src/Illuminate
/Foundation/Application.php
on line 402
This is my composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "5.0.14",
"phpunit/phpunit": "4.7.*#dev",
"theseer/fxsl": "1.0.*#dev",
"theseer/phpdox": "0.6.6",
"squizlabs/php_codesniffer": "1.4.6",
"phpmd/phpmd": "2.0.0",
"h4cc/phpqatools": "dev-master",
"phploc/phploc": "2.0.2",
"sebastian/phpcpd": "2.0.1",
"monolog/monolog": "1.13.0",
"patchwork/utf8": "1.2.1",
"phpdocumentor/phpdocumentor": "v2.0.1",
"mayflower/php-codebrowser": "1.1.0-beta1",
"pear/console_commandline": "dev-trunk",
"pear/log": "dev-master",
"pear/pear_exception": "1.0.0",
"phing/phing": "2.6.1"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev"
}
I can run composer update --no-scripts.
I've searched for any composer.php files with sudo find . -print | grep -i 'compiled.php'. The only one I have is ./vendor/symfony/dependency-injection/Tests/Fixtures/php/services9_compiled.phpwhich does not correspond with the compiled.php file several other people have suggested deleting for other people who have had this problem.
I think you are using a Laravel 4 composer.json. One of the big changes from Laravel 4 to Laravel 5 is the usage of namespaces.
Also a lot of paths have been modified, so just installing Laravel 5 over an existing Laravel 4 is not possible.
Better to install a fresh Laravel 5 and follow this guide:
http://laravel.com/docs/master/upgrade#upgrade-5.0
For reference here is my composer.json (notice the psr-4 in the autoload section)
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
The composer file could be very well be 30 days older and not updated.
You would have to run this command from the path of the code folder using either a vitrtual box or cmd/gitbash/terminal:
curl -sS https://getcomposer.org/installer | php
once downloaded, move the composer.phar file to the composer folder , normally its located at:
sudo mv composer.phar usr/bin/local/composer
then run the composer update to regenerate the autoloaded files.

Laravel: Issues with ServiceProvider | Error: Class '...ServiceProvider' not found in bootstrap/compiled.php on line #

I have been working on the same app for a little bit now, and I am moving it over to Laravel. This is not only my first experience with Laravel, but my first time using a PHP framework. It is awesome so far.
I have run into a problem in my testing, I am getting an error: Error Output: PHP Fatal error: Class 'my-app/Repositories/RepositoryServiceProvider' not found in /var/www/laravel/bootstrap/compiled.php on line 4259
I am wondering what causes this error and how I can fix it . It gives me the direct line that is problematic. But I have no idea how to solve this issue.
I have tried a number of solutions including
composer install
composer update
composer dump-autoload
and others as well.
I have also attempted deleting the compiled.php file all together, but then it trips the same error on a different file. What is it causing this error, and how can I go about debugging it?
This is my RepositoryServiceProvider.php file that is being problematic:
<?php namespace my-app\Repositories;
use Invite;
use Illuminate\Support\ServiceProvider;
use my-app\Repositories\Invite\EloquentInviteRepository;
class RepositoryServiceProvider extends ServiceProvider {
/**
* Register the Invite Repository
*
* #return void
*/
public function registerInviteRepository()
{
$this->app->bind('my-app\Repositories\Invite\InviteRepository', function($app)
{
return new EloquentInviteRepository( new Invite );
});
}
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"way/generators": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
This is the specific line in compiled.php that is giving the issue:
{
return new $provider($app);
}
You guys have been a huge resource in the past.
I've experienced almost 24 hours of coding downtime because of this probably simple problem, and I've restored and rebuilt twice, only getting back to this error.
Thanks for help in advance!!
Have you tried registering your provider under 'providers' array of /app/cofig/app.php then do a composer dump-autoload -o

Categories