laravel 升级到 5.2
Posted
技术标签:
【中文标题】laravel 升级到 5.2【英文标题】:laravel upgrade to 5.2 【发布时间】:2020-08-26 22:22:18 【问题描述】:我正在将 Laravel 从 5.1 升级到 5.2,我的 auth.php
return [
/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/
'driver' => 'eloquent',
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/
'model' => App\Models\User::class,
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
'table' => 'users',
/*
|--------------------------------------------------------------------------
| Password Reset Settings
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You can also set the name of the
| table that maintains all of the reset tokens for your application.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
];
新的更新应该是什么样子。该文档有一个 laravel 5.2 的 auth.php 示例,但我不确定我应该在文件中留下什么以及应该修改什么。当我尝试登录我的应用程序时,我得到 未定义身份验证保护 [web]。
【问题讨论】:
【参考方案1】:您应该将整个配置文件替换为this,然后根据您的旧配置文件将选项更改为所需的值。
根据您在此处发布的内容,您唯一需要更改的是用户提供者:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class, // Changed from App\User::class
],
],
以及密码重置邮件的查看路径:
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'emails.password', // Changed from auth.emails.password
'table' => 'password_resets',
'expire' => 60,
],
],
虽然将邮件视图移动到 Laravel 建议的新默认位置可能是一个更好的主意:auth.emails.password
Upgrading To 5.2.0 From 5.1:
使用新副本更新文件后,设置您的 身份验证配置选项根据其所需的值 你的旧配置文件。如果你使用的是典型的 Eloquent Laravel 5.1 中可用的基于身份验证服务,大多数值 应该保持不变。
请特别注意其中的 passwords.users.email 配置选项 新建 auth.php 配置文件并验证查看路径 与您的应用程序的实际视图路径匹配,作为默认路径 在 Laravel 5.2 中改变了这个观点。如果默认值在 新的配置文件与您现有的视图不匹配,请更新 配置选项。
【讨论】:
谢谢。我更新了它。现在我的应用程序无法在 .env 中看到变量。当我尝试使用 $_ENV 访问此变量时,我得到“未定义索引 @marmahan 您可能应该创建一个新问题并在那里发布所有详细信息,仅凭一条评论很难知道问题出在哪里。 等待被允许。 *** 不允许我开始一个新的以上是关于laravel 升级到 5.2的主要内容,如果未能解决你的问题,请参考以下文章
在升级laravel 5.2到5.3之后,无法在Route :: model中绑定模型
从 Laravel 5.2 更新到 5.3 后,调用数组上的成员函数 all()