在Laravel中创建用户表

Sni*_*ers 4 php authentication laravel

我在laravel的users表上遇到了一些麻烦。很久以前,我已经删除了那些默认表。现在,我尝试使用Auth,但无法注册。因为数据库中没有表。但是我也不能创建表,php artisan migrate.因为我已经删除了那些迁移表。所以我想再次创建这些表。但是我找不到默认文件。

而且make:auth不会带来表格...我需要自己重新创建它。我记得有两个不同的表,然后是一个用户名和重置密码?有谁知道我可以再去哪里找桌子?

Sur*_*ari 11

只需运行这些命令

php artisan make:migration create_users_table
php artisan make:migration create_password_resets_table
Run Code Online (Sandbox Code Playgroud)

在您的迁移中create_users_table

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }
Run Code Online (Sandbox Code Playgroud)

在您的迁移中,create_password_resets_table

 public function up()
    {
        Schema::create('password_resets', function (Blueprint $table) {
            $table->string('email')->index();
            $table->string('token');
            $table->timestamp('created_at')->nullable();
        });
    }
Run Code Online (Sandbox Code Playgroud)

在那之后

php artisan migrate:refresh
Run Code Online (Sandbox Code Playgroud)

PS:这将重置您的数据库或仅运行

php artisan migrate
Run Code Online (Sandbox Code Playgroud)

编辑:如果面临错误 1071 Specified key was too long; max key length is 767 bytes

在您AppServiceProvider.php添加此

use Illuminate\Support\Facades\Schema; //this

public function boot()
{
    Schema::defaultStringLength(191); //this
}
Run Code Online (Sandbox Code Playgroud)