laravellaravel-artisanartisan-migrate

error when executing php artisan migrate seed in console


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


Solution

  • 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...