php-laravel框架用户验证(Auth)模块解析(一)
发布日期:2025-05-03 03:37:28 浏览次数:12 分类:精选文章

本文共 671 字,大约阅读时间需要 2 分钟。

Laravel Auth初始化与配置指南

一、初始化

使用php artisan命令进行初始化:

  • php artisan make:auth 生成用户认证相关文件
  • php artisan migrate 执行数据库迁移(生成users表和password_resets表)
  • php artisan make:auth 会修改或生成以下文件:

  • routes/web.php 和 app/Http/Controllers/HomeController.php

    • 注册、登录、找回密码路由由Auth::routes()控制
    • route::get('/home', 'HomeController@index') -> name('home') 需登录访问
  • resources/views/auth/* 和 resources/views/layouts/* 模板

    • 初始化完成后,访问http://[yourhost]/login可见生成页面
  • 二、配置config/auth.php

    config/auth.php是Laravel Auth的核心配置文件,通常无需修改主要项

  • web和api验证方式:

    • web使用session验证用户
    • api使用token验证用户
  • 服务提供者配置:

    • 'users' 驱动使用eloquent(默认数据库驱动)
    • model指定模型类:App\User::class
  • 重置密码配置:

    • 'users' 表关联password_resets表
    • exprire时间为60秒
  • 本文将为您详细解析Laravel Auth配置文件结构

    上一篇:php-laravel框架用户验证(Auth)模块解析(三)登录模块
    下一篇:PHP-GD库-分类整理

    发表评论

    最新留言

    关注你微信了!
    [***.104.42.241]2026年06月07日 17时23分43秒