error when executing php artisan migrate seed in console - laravel

I write php artisan migrate:fresh --seed in the console of the root folder of a project, when I run this command, it takes near to 1 minute then it returns \
In PackageServiceProvider.php line 14:
syntax error, unexpected 'Package' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
PackageServiceProvider.php:
namespace Spatie\LaravelPackageTools;
use Carbon\Carbon;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use ReflectionClass;
use Spatie\LaravelPackageTools\Exceptions\InvalidPackage;
abstract class PackageServiceProvider extends ServiceProvider
{
protected Package $package; /* line 14 */
abstract public function configurePackage(Package $package): void;
public function register()
{
$this->registeringPackage();
$this->package = new Package();
$this->package->setBasePath($this->getPackageBaseDir());
$this->configurePackage($this->package);
if (empty($this->package->name)) {
throw InvalidPackage::nameIsRequired();
}
foreach($this->package->configFileNames as $configFileName) {
$this->mergeConfigFrom($this->package->basePath("/../config/{$configFileName}.php"), $configFileName);
}
$this->packageRegistered();
return $this;
}
.
.
.
.
}
the project's author's PHP version: 7.4.19
my PHP version: 7.3.27
I'm noob in laravel, so if I have to show up with more info about the issue tell me. \
edit
after updating the PHP version to 7.4.21
I wrote the command and it returned
C:\xampp\htdocs\Business-Manager>php artisan migrate:fresh --seed
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> y
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO) (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
at C:\xampp\htdocs\Business-Manager\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
688▕ // If an exception occurs when attempting to run a query, we'll format the error
689▕ // message to include the bindings with SQL, which will make this exception a
690▕ // lot more helpful to the developer instead of just the database's errors.
691▕ catch (Exception $e) {
➜ 692▕ throw new QueryException(
693▕ $query, $this->prepareBindings($bindings), $e
694▕ );
695▕ }
696▕
1 C:\xampp\htdocs\Business-Manager\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDO\Exception.php:18
Doctrine\DBAL\Driver\PDO\Exception::("SQLSTATE[HY000] [1045] Access denied for user 'forge'#'localhost' (using password: NO)")
2 C:\xampp\htdocs\Business-Manager\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:43
Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException))
my MySQL accounts :
enter image description here

Your problem is that protected Package $package; is PHP 7.4, it should be like protected $package;.
As you can see in the source code, it required php ^7.4 or ^8.0, so you have to change your PHP to either of those.
This is another place to see the composer package you are downloading, to see more info about it...

import suitable class in the top.
use Facade\Ignition\Support\Packagist\Package;

Related

Laravel phpunit tests fails with PDOException: SQLSTATE[HY000]: General error: 1 near "0": syntax error

After a composer update in my Laravel project all my tests fails. My Laravel version is 9.24.0
I use PHPUnit tests in a Docker container on Alpine Linux image (php:8.1-fpm-alpine).
pdo_sqlite and sqlite3 php modules are both enabled and loaded (php -m said).
When I run docker-compose run --rm phpunit I get this result for all my tests:
Domain\Customer\Tests\Address\AddressModelTest::myTestName
Illuminate\Database\QueryException: SQLSTATE[HY000]:
General error: 1 near "0": syntax error (SQL: CREATE TABLE ...
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:759
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:719
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:545
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php:109
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:394
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:241
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:338
/var/www/html/database/migrations/2021_11_17_154600_alter_table_modify_content_column_type.php:18
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:482
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:400
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:409
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:210
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php:36
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:740
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:210
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:175
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:118
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:87
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:616
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:99
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php:41
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:651
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php:139
/var/www/html/vendor/symfony/console/Command/Command.php:308
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php:124
/var/www/html/vendor/symfony/console/Application.php:998
/var/www/html/vendor/symfony/console/Application.php:299
/var/www/html/vendor/symfony/console/Application.php:171
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php:102
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php:194
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:263
/var/www/html/vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php:286
/var/www/html/vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php:465
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php:80
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:47
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:22
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:123
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:92
/var/www/html/tests/MultitenancyTestCase.php:34
Caused by
PDOException: SQLSTATE[HY000]: General error: 1 near "0": syntax error
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:538
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:752
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:719
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:545
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php:109
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:394
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:241
/var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:338
/var/www/html/database/migrations/2021_11_17_154600_alter_table_modify_content_column_type.php:18
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:482
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:400
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:409
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:210
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/View/Components/Task.php:36
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:740
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:210
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:175
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:118
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:87
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:616
/var/www/html/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:99
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php:41
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
/var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:651
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php:139
/var/www/html/vendor/symfony/console/Command/Command.php:308
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php:124
/var/www/html/vendor/symfony/console/Application.php:998
/var/www/html/vendor/symfony/console/Application.php:299
/var/www/html/vendor/symfony/console/Application.php:171
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php:102
/var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php:194
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:263
/var/www/html/vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php:286
/var/www/html/vendor/laravel/framework/src/Illuminate/Testing/PendingCommand.php:465
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php:80
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:47
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php:22
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:123
/var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:92
/var/www/html/tests/MultitenancyTestCase.php:34
UPDATE:
The content of 2021_11_17_154600_alter_table_modify_content_column_type.php file is:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('menu_contents', function (Blueprint $table) {
$table->mediumText('content')->change();
}); # this is the 18. line
I tried to downgrade laravel/framework:9.3.0, but itsn't helped.
Any idea how can I fix this?
See here for recent issue in doctrine/dbal https://github.com/doctrine/dbal/issues/5584 rolling back to 3.3.7 resolved my issues.

How to Install Swagger-UI to Laravel 6 API for doumentation?

Installing Swagger for the First Time in laravel 6. https://github.com/DarkaOnLine/L5-Swagger.
composer require "darkaonline/l5-swagger"
php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"
On generating command
php artisan l5-swagger:generate
Getting Error like:
php artisan l5-swagger:generate
Regenerating docs
ErrorException : Required #OA\Info() not found
at D:\XMAPP\htdocs\minidmsapi\vendor\zircote\swagger-php\src\Logger.php:39
35| $this->log = function ($entry, $type) {
36| if ($entry instanceof Exception) {
37| $entry = $entry->getMessage();
38| }
> 39| trigger_error($entry, $type);
40| };
41| }
42|
43| /**
Exception trace:
1 trigger_error("Required #OA\Info() not found")
D:\XMAPP\htdocs\minidmsapi\vendor\zircote\swagger-php\src\Logger.php:39
2 OpenApi\Logger::OpenApi\{closure}("Required #OA\Info() not found")
D:\XMAPP\htdocs\minidmsapi\vendor\zircote\swagger-php\src\Logger.php:71
Please use the argument -v to see more details.
please Help me for generating swagger documentation
Required #OA\Info() is required to initialize your swagger documentation and then use proper annotation to parse. Annotations are only parsed inside /** DocBlocks. Here you go for initial annotations swagger-php#usage

Generating models from existing database at once

I'm trying to generate models from an existing database at once without having to do it separately for all tables. I have tried to do this with reliese/laravel. I have executed:
php artisan -v code:models
However, I'm getting the following error.
ErrorException : mkdir(): Invalid path
at C:\xampp\htdocs\schaden\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:466
462| if ($force) {
463| return #mkdir($path, $mode, $recursive);
464| }
465|
466| return mkdir($path, $mode, $recursive);
467| }
468|
469| /**
470| * Move a directory.
Exception trace:
1 mkdir("")
C:\xampp\htdocs\schaden\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:466
I'm not posting the full error stack here. Can anyone help?
Probably the best solution is using the package Eloquent Model Generator that you can find on github at https://github.com/krlove/eloquent-model-generator.
Then you can easily use, for example, php artisan krlove:generate:model User --table-name=users or php artisan krlove:generate:model MyModel --table-name=my_models and use some of the package options.

JWTGenerateCommand::handle() does not exist

I am using Laravel 5.4 and JWT Auth Library for user authentication in API development. After installation while i am running php artisan jwt:generate then it throws me error of
Method Tymon\JWTAuth\Commands\JWTGenerateCommand::handle() does not exist
Any idea what i am missing ?
This error generally display when you install jwt package in laravel 5.5 version. then after you set service providers and run following command.
php artisan jwt:generate
then you seen this error message in terminal.
how to resolve it? simple follow this step
Step - 1 Re-install package
composer require tymon/jwt-auth:dev-develop --prefer-source
or the following is a new release package use laravel 6.X
composer require tymon/jwt-auth:1.0.*
in this developement version this errors fixed.
Step - 2 Set Service Provider
'providers' => [
....
Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class to
Tymon\JWTAuth\Providers\LaravelServiceProvider::class
],
Step - 3 Generate key
php artisan jwt:secret
i found this solution from here https://laravelcode.com/post/method-tymonjwtauthcommandsjwtgeneratecommandhandle-does-not-exist
Go to JWTGenerateCommand.php file located in vendor/tymon/src/Commands and paste this method
public function handle() { $this->fire(); }
It's never a great idea to change anything in the vendor folder but the there's two ways to deal with this ...
Generate a random string yourself and just change the value in the JWT config file.
Go to Tymon\JWTAuth\Commands\JWTGenerateCommand and change the fire method to handle.
go to given file path
vendor/tymon/jwt-auth/src/Commands/JWTGenerateCommand.php
change function name
public function fire() to public function handle()
run command:
php artisan jwt:generate
I'm publishing this answer because I have crash in this error more than one time.
The only solution I found that it works with Laravel 5.6 is the following:
Add "tymon/jwt-auth": "1.0.0-rc.1" to composer.json and run composer update
Open config/app.php and add the following:
config/app.php:
'providers' => [
/*
* JWT Service Provider...
*/
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],
'aliases' => [
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
],
Execute:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
Finally, execute: php artisan jwt:secret
After all that, when I hit my endpoint for login I got the following exception:
Class Tymon\JWTAuth\Providers\JWT\NamshiAdapter does not exist
This was fixed by:
Open config/jwt.php and change the following:
config/jwt.php:
'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,
Finally, note that in order to work your User model should be defined as follows:
class User extends Authenticatable implements JWTSubject
{
...
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
...
}
I can advise one solution. Go to JWTGenerateCommand.php file located in vendor/tymon/src/Commands and paste this part of code public function handle() { $this->fire(); }
I know this is not an elegant solution, but it works. I hope this might help until official fix arrive.
see here for more info
Change fire() function to handle() in this path
vendor/tymon/jwt-auth/src/commands/JWTGenerateCommand.php
In the file path: /vendor/tymon/jwt-auth/src/Commands/JWTGenerateCommand.php
Add public function
public function handle()
{
$this->fire();
}

cron scheduler in laravel 4

I am trying to set cron for a command or controller action but it seemed to be not working for me. Please see below what I have tried
I have been trying to set up scheduler as per your instructions with no result.
When I try:
1. /usr/local/bin/php /home/mysite/public_html/protected/app/start/artisan cron:run it gives error
Could not open input file: /home/mysite/public_html/protected/app/start/artisan
2. /usr/local/bin/php /home/mysite/public_html/protected/app/controllers/TestController.php
it gives error Fatal error: Class 'BaseController' not found in
3. /usr/local/bin/php -q /home/mysite/public_html/protected/app/start/artisan cron:run
Error-Could not open input file:
4. php /var/www/com/mysite.com/artisan cron:run
Status: 404 Not Found No input file specified.
/usr/local/bin/php home/opendesk/public_html/protected/app/start/artisan.php and in artisan.php I do like Artisan::add(new CronRunCommand);
Error Fatal error: Class 'Artisan' not found
/usr/local/bin/php /home/opendesk/public_html/protected/app/start/artisan.php
when in artisan.php I change it to $artisan->add(new CronRunCommand);
Error Fatal error: Call to a member function add() on a non-object
None of it seems to work. I have been read many SO and google posts but cant find a solution to this. hoping to get some help here
At first. Task Scheduling not available in laravel 4, you need use newest version.
At second. What a path /home/mysite/public_html/protected/app/start/artisan? Can you show application folder structure?
However artisan its file in application root folder in default installation. For sample - my application placed in \var\www\myaplication then artisan placed in \var\www\myaplication\artisan. And i call this php \var\www\myaplication\artisan or better, change current dir to cd \var\www\myaplication and run php artisan.
At trith artisan cron can not prepare controller method. You need create a cron task in file App\Console\Kernel
<?php
namespace App\Console;
use DB;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
\App\Console\Commands\Inspire::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
DB::table('recent_users')->delete();
})->daily();
}
}
For more details read documenation this very useful!

Resources