PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

Laravel 5.2 用户认证,怎样用Flash Message显示错误信息?

原创
2016-08-04 09:20:16 1037浏览

默认的提示是这样的:

怎样改成用$request->session()->flash()来显示这些信息呢?而且只显示第一条。
要求不在默认的位置(也就是图片里面的红字位置)显示出错信息。

回复内容:

默认的提示是这样的:

怎样改成用$request->session()->flash()来显示这些信息呢?而且只显示第一条。
要求不在默认的位置(也就是图片里面的红字位置)显示出错信息。

多次参考Laravel中文文档后自己解决了。
在AuthController里面手动验证。
登录函数:

use Auth;
use Validator;
use Illuminate\Http\Request;

public function postLogin(Request $request) {
    $validator = Validator::make($request->all(), [
        'username' => 'bail|required|min:5|max:30|unique:users',
        'password' => 'bail|required|min:8|max:50',
    ]);
    
    if ($validator->fails()) {
        $errors = $validator->errors()->all();
        if (count($errors) > 0) {
            Flash(implode('
', $errors), 'error'); //我使用了laracasts/flash这个扩展包,如果你没安装,用$request->session->flash()也是一样的 } return redirect('//m.sbmmt.com/m/login') ->withInput(); //不使用->withErrors就不会显示红字 } //验证登录代码省略... }

注册函数类似。

我想知道你的变量如何替换成中文的

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。