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 SpatieLaravelPackageTools;
use CarbonCarbon;
use IlluminateSupportFacadesView;
use IlluminateSupportServiceProvider;
use IlluminateSupportStr;
use ReflectionClass;
use SpatieLaravelPackageToolsExceptionsInvalidPackage;
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:xampphtdocsBusiness-Manager>php artisan migrate:fresh --seed
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command? (yes/no) [no]:
> y
IlluminateDatabaseQueryException
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
at C:xampphtdocsBusiness-ManagervendorlaravelframeworksrcIlluminateDatabaseConnection.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:xampphtdocsBusiness-ManagervendordoctrinedballibDoctrineDBALDriverPDOException.php:18
DoctrineDBALDriverPDOException::("SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)")
2 C:xampphtdocsBusiness-ManagervendordoctrinedballibDoctrineDBALDriverPDOConnection.php:43
DoctrineDBALDriverPDOException::new(Object(PDOException))
my MySQL accounts :
enter image description here
2
Answers
Your problem is that
protected Package $package;
is PHP7.4
, it should be likeprotected $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.