Php artisan make:auth 命令未定义

Php artisan make:auth command is not defined

我正在尝试 运行 在 Laravel 5.2 中执行此命令,但它不起作用:

php artisan make:auth 

并提示这些语句:

[InvalidArgumentException]
  Command "make:auth" is not defined
  Did you mean one of these?  


      make:test
      make:request
      make:migration
      make:seeder
      make:middleware
      make:controller
      make:provider
      make:policy
      make:event
      make:console
      make:job
      make:listener
      make:model
      make:command

对于Laravel >=6

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

参考:Laravel Documentation for authentication

看起来您没有使用 Laravel 5.2,这些是 L5.2 中可用的 make 命令,您不仅缺少 make:auth 命令

    make:auth           Scaffold basic login and registration views and routes
    make:console        Create a new Artisan command
    make:controller     Create a new controller class
    make:entity         Create a new entity.
    make:event          Create a new event class
    make:job            Create a new job class
    make:listener       Create a new event listener class
    make:middleware     Create a new middleware class
    make:migration      Create a new migration file
    make:model          Create a new Eloquent model class
    make:policy         Create a new policy class
    make:presenter      Create a new presenter.
    make:provider       Create a new service provider class
    make:repository     Create a new repository.
    make:request        Create a new form request class
    make:seeder         Create a new seeder class
    make:test           Create a new test class
    make:transformer    Create a new transformer.

请确保您的 composer.json 文件中有此依赖项

    "laravel/framework": "5.2.*",

然后运行

    composer update

Laravel 8

更新

laravel/ui 仍然有效,但被认为是遗留的。考虑使用 Laravel Breeze or Laravel Jetstream.

Laravel 6

更新

现在 Laravel 6 is released 你需要安装 laravel/ui.

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

如果您在项目中使用 React 或 Bootstrap,您可以将 vue 更改为 reactbootstrap(参见 Using React)。

然后你需要执行迁移和编译前端

php artisan migrate
npm install && npm run dev

来源:Laravel Documentation for authentication

Want to get started fast? Install the laravel/ui Composer package and run php artisan ui vue --auth in a fresh Laravel application. After migrating your database, navigate your browser to http://your-app.test/register or any other URL that is assigned to your application. These commands will take care of scaffolding your entire authentication system!

注意:只有当你想使用脚手架时,你才可以使用默认的用户模型和 Eloquent 身份验证驱动程序。

在Laravel 6.0 make:auth 中不再存在。 Read more here

A- Shorthand:

11 月 18 日更新: Taylor 刚刚发布 Laravel Installer 2.3.0 添加了一个新的“--auth”标志来创建一个安装了身份验证脚手架的新项目!

更新 laravel 安装程序 read here

这意味着我们可以做到:

laravel new project --auth

cd project

php artisan migrate

npm install
npm run dev

这是 B 部分中的 shorthand 个命令。Also read more here


B - 详情:

遵循这些三个步骤

步骤 1 - 首先执行此操作:

laravel new project

cd project

composer require laravel/ui --dev

注: Laravel UI Composer 包是一个新的第一方包,它提取 Laravel 项目的 UI 部分(前端脚手架通常随 Laravel 的早期版本提供) 到一个单独的 laravel/ui 包中。单独的包使 Laravel 团队能够独立于主要框架和主要 Laravel 代码库更新、开发和版本化 UI 脚手架包。

步骤 2 - 然后执行此操作:

php artisan ui bootstrap --auth
php artisan migrate

php artisan ui vue --auth
php artisan migrate

而不是

php artisan make:auth  ( which works for Laravel 5.8 and older versions )

更多选项 here

php artisan ui:auth

以上命令将只生成 auth 路由、HomeController、auth 视图和 app.blade.php 布局文件。

您还可以仅通过以下方式生成视图:

php artisan ui:auth --views

如果您之前已经运行该命令,控制台命令将提示您确认覆盖授权文件。

// Generate basic scaffolding...
php artisan ui vue
php artisan ui react

还有:

// Generate login / registration scaffolding...
php artisan ui vue --auth
php artisan ui react --auth

看差异read this article

第3步-然后你需要做:

npm install
npm run dev

简而言之,您需要做的就是

composer require laravel/ui --dev

php artisan ui vue --auth 然后 migrate php artisan migrate.

只是为了概述 Laravel 身份验证

Laravel 身份验证设施附带 GuardProvidersGuards 定义如何针对每个请求对用户进行身份验证,而 提供商 定义如何从您的持久存储中检索用户。

数据库注意事项 - 默认情况下 Laravel 在您的应用程序目录中包含一个 App\User Eloquent 模型。

Auth 命名空间 - App\Http\Controllers\Auth

Controllers -RegisterController、LoginController、ForgotPasswordController、ResetPasswordController,名字都有意义,通俗易懂!

Routing - Laravel/ui 包提供了一种快速的方法来使用一些简单的命令(如开头所述的那样)构建身份验证所需的所有路由和视图make:auth).

您可以禁用任何新创建的控制器,例如。 G。 RegisterController 并修改您的路由声明,如 Auth::routes(['register' => false]); 有关详细信息,请查看 Laravel Documentation.

在 Laravel 6 应用程序中,make:auth 命令不再存在。

Laravel UI 是一个新的第一方包,它将 Laravel 项目的 UI 部分提取到单独的 laravel/ui 包中。单独的包使 Laravel 团队能够独立于主 Laravel 代码库对 UI 包进行迭代。

您可以通过 composer 安装 laravel/ui 软件包:

composer require laravel/ui

ui:auth 命令

除了新的ui命令之外,laravel/ui包还附带了另一个用于生成auth脚手架的命令:

php artisan ui:auth

如果你运行 ui:auth命令,它会生成auth路由,一个HomeControllerauth views,和一个 app.blade.php 布局文件。


如果您想单独生成视图,请改为键入以下命令:

php artisan ui:auth --views

如果要同时生成auth脚手架:

php artisan ui vue --auth
php artisan ui react --auth

php artisan ui vue --auth 命令将创建身份验证所需的所有视图并将它们放在 resources/views/auth 目录中

ui 命令还将创建一个 resources/views/layouts 目录,其中包含应用程序的基本布局。所有这些视图都使用 Bootstrap CSS 框架,但您可以随意自定义它们。

更多细节如下。 laravel-news & documentation

只需执行这两个步骤即可。

composer require laravel/ui
php artisan ui:auth

这两个命令在我的项目中对我有用

composer require laravel/ui --dev

然后

php artisan ui:auth

在 composer.json 文件中检查 laravel/framework 版本,

如果是“^6.0”或高于“^5.9”,

您必须使用 php artisan ui:auth 而不是 php artisan make:auth

在使用它之前,您必须通过调用安装新的依赖项 composer require laravel/ui --dev 在当前目录下。

如果您使用 >5 版本的 laravel 那么您将使用。

composer require laravel/ui --dev **or** composer require laravel/ui

然后

php artisan ui:auth

您可以使用laravel/breeze

composer require laravel/breeze --dev

然后

php artisan breeze:install

然后

npm install

你可以查看documentation

以下 CLI 命令通常用于设置 Laravel 6.x、7x、8.x 版本:

composer create-project --prefer-dist laravel/laravel blade-example-app

cd blade-example-app

composer require laravel/ui

php artisan ui bootstrap --auth

npm install && npm run dev

php artisan migrate

php artisan serve

Please run the billow commands step by step in the case of laravel 9

composer require laravel/ui
php artisan ui bootstrap --auth
npm install
npm install resolve-url-loader@^5.0.0 --save-dev --legacy-peer-deps
npm run dev

Hope it will be helpful.