Laravel Auth登录页面只是刷新

11 浏览
0 Comments

Laravel Auth登录页面只是刷新

我正在使用Laravel 5.4。我运行了make:auth命令来生成我的认证控制器和视图。我可以成功注册一个新账户,因为它已经显示在我的数据库中。但是当我尝试登录时,登录页面只是刷新,没有任何错误提示。在登录控制器中,我将重定向设置为'/home',但这并没有发生。有什么可能导致这个问题?我觉得这可能是因为我对允许用户使用用户名而不是电子邮件进行登录进行了必要的修改。但是我不确定为什么我的登录功能无法正常工作,而其他功能都正常。以下是我的登录控制器代码。

use AuthenticatesUsers;
/**
 * 登录后要重定向的位置.
 *
 * @var string
 */
protected $redirectTo = '/home';
/**
 * 创建一个新的控制器实例.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest', ['except' => 'logout']);
}
public function username()
{
    return 'username';
}

0
0 Comments

问题原因:在使用Laravel 8.0时,登录页面只会刷新,没有其他有效的解决方法。直到我检查了.env文件中设置的APP_URL时才找到解决方法。因为我在同一台本地主机上设置了其他应用程序,并使用不同的端口,所以我将APP_URL从http://localhost更改为http://localhost:8003/,即指定此应用程序所在的端口。

解决方法:

1. 在.env文件中将APP_URL的值更改为指定应用程序所在的端口。例如,将APP_URL从http://localhost更改为http://localhost:8003/。

2. 重新生成APP_KEY。可以使用以下命令生成新的APP_KEY:php artisan key:generate。

3. 刷新数据库迁移。可以使用以下命令刷新数据库迁移:php artisan migrate:refresh。

希望这篇文章能帮助到其他人,尽管花费了我3天的时间才找到解决方法。

0
0 Comments

在运行php artisan make:auth之后,你还需要运行php artisan migrate来执行迁移,你做过这个操作吗?

This issue can occur if the migrations have not been run after running the php artisan make:auth command. The make:auth command generates the necessary views and routes for authentication, but it does not create the required database tables.

To fix this issue, you need to run the migrations using the php artisan migrate command. This command will create the necessary tables in your database for authentication.

If you have already run the php artisan migrate command and the issue still persists, you can try the following solutions:

1. Clear the cache: Run the php artisan cache:clear command to clear the application cache. This can help resolve any caching issues that may be causing the login page to refresh.

2. Check the session configuration: Ensure that the session driver is set correctly in your config/session.php file. The default driver is usually set to file, but you can also try using database or redis as the driver.

3. Verify the redirect route: Double-check the redirect property in the app/Http/Controllers/Auth/LoginController.php file. Make sure it is set to the correct route that you want to redirect to after successful login.

4. Check for any custom middleware: If you have any custom middleware applied to the login route, make sure it is not causing any conflicts or issues. Temporarily remove any custom middleware to see if it resolves the problem.

By following these steps, you should be able to resolve the issue of the Laravel Auth login page refreshing.

0
0 Comments

Laravel Auth Login Page Just Refreshes问题的出现原因可能是路由未正确处理。解决方法可以尝试在web.php文件中添加Auth::routes();

具体的解决方法可以参考以下步骤:

1. 检查路由是否被正确处理。

2. 在web.php文件中添加Auth::routes();

如果以上方法无法解决问题,可以参考laravel 5.3 new Auth::routes()资源中的讨论,寻找其他可能的解决方案。

0