gpt4 book ai didi

Laravel 迁移创建用户 "unexpected ' use' (T_USE)"SQLite

转载 作者:行者123 更新时间:2023-12-01 15:24:18 24 4
gpt4 key购买 nike

我正在使用最新版本的 Laravel。新鲜的项目。刚刚创建了 make:auth 函数。

我的目标是向注册字段添加其他字段。原始模型只需要姓名、电子邮件和密码。我正在使用 SQLite 和 PHP 7.1.19

我想添加名字、姓氏和年龄。不知何故,我收到如下所示的错误。

有人可以详细说明我做错了什么吗?

Symfony\Component\Debug\Exception\FatalThrowableError  : syntax error, unexpected 'use' (T_USE) at /Users/sebastiaan/Documents/Code/auth/auth-example/database/migrations/2014_10_12_000000_create_users_table.php:3
1| <?php
2|
> 3| use Illuminate\Support\Facades\Schema;
4| use Illuminate\Database\Schema\Blueprint;
5| use Illuminate\Database\Migrations\Migration;
6|
7| class CreateUsersTable extends Migration
8| {
9| /**

Exception trace:

1 Illuminate\Filesystem\Filesystem::requireOnce("/Users/sebastiaan/Documents/Code/auth/auth-example/database/migrations/2014_10_12_000000_create_users_table.php")
/Users/sebastiaan/Documents/Code/auth/auth-example/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:448

2 Illuminate\Database\Migrations\Migrator::requireFiles()
/Users/sebastiaan/Documents/Code/auth/auth-example/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:90

Please use the argument -v to see more details.

这就是迁移文件现在的样子。
<?php
 
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('firstname');
$table->string('lastname');
$table->integer('age');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

最佳答案

PHP 版本不支持命名空间和 use 语句 < 5.3
请使用 <?php echo phpversion(); ?> 检查您的 php 版本并检查它是否低于 5.3

否则类(class)看起来不错。如果在开始的 php 标签之前有空格,你会收到一个不同的错误,比如

Namespace declaration statement has to be the very first statement or after any declare call in the script



情况似乎也并非如此。

更新 :

另一种可能发生的方式是由于某些字符就在 use 语句之前。例如这个代码:
<?php 

test

use \App\User;

class....
?>

如果您观察到存在 test在 use 语句之前的 word 错误地这会导致同样的错误。

回到这里的相关性:

如果您从某个网站复制了迁移类以防万一,您可能也复制了一些不明显的空白字符。我会建议在使用语句之前做一个退格并检查这样的空格。如果你在 VIM 编辑器中打开这个文件,你可能也会看到这样的情况。

关于Laravel 迁移创建用户 "unexpected ' use' (T_USE)"SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55126381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com