laravel8项目搭建

作者: charmingcheng | 来源:发表于2021-07-16 10:15 被阅读0次

    安装 Laravel8

    项目使用homestead环境
    Laravel 使用 Composer 来管理项目依赖。因此,在使用 Laravel 之前,请确保您的机器上已经安装了 Composer。

    通过 Composer 创建项目

    在终端中运行 create-project 命令来安装 Laravel:

    composer create-project --prefer-dist laravel/laravel laravel-im
    

    当前最新版本是8.x

    登录功能

    登录功能使用 laravel/ui 插件

    composer require laravel/ui
    
    php artisan ui vue --auth
    

    打开浏览器,浏览本地hosts映射好的地址:


    image.png

    修改user数据库迁移文件

    public function up()
        {
            Schema::create('users', function (Blueprint $table) {
                $table->id();
                $table->string('username');
                $table->string('nickname');
                $table->string('email')->unique()->nullable();
                $table->string('phone')->unique()->nullable();
                $table->timestamp('email_verified_at')->nullable();
                $table->string('password');
                $table->rememberToken();
                $table->timestamps();
            });
        }
    

    生成user填充文件,填充users表

    php artisan make:seeder UserSeeder
    
    public function run()
        {
            User::create([
                'username' => 'admin',
                'nickname' => '管理员',
                'email'    => 'admin@qq.com',
                'phone'    => '18288888888',
                'password' => bcrypt('123456')
            ]);
        }
    

    注意:取消 laravel/ui 自带的注册功能路由:

    // routes/web.php
    Auth::routes(['register' => false]);
    

    码云地址:https://gitee.com/charming-cheng/laravel-im

    相关文章

      网友评论

        本文标题:laravel8项目搭建

        本文链接:https://www.haomeiwen.com/subject/xoeppltx.html