Laravel 5.2 user authentication, how to use Flash Message to display error messages?

WBOY
Release: 2016-08-04 09:20:16
Original
1249 people have browsed it

The default prompt is like this:
Laravel 5.2 user authentication, how to use Flash Message to display error messages?
How to change to use $request->session()->flash() to display this information? And only the first one is displayed.
It is required that the error message is not displayed in the default position (that is, the red text position in the picture).

Reply content:

The default prompt is like this:
Laravel 5.2 user authentication, how to use Flash Message to display error messages?
How to change to use $request->session()->flash() to display this information? And only the first one is displayed.
It is required that the error message is not displayed in the default position (that is, the red text position in the picture).

I solved it myself after referring to Laravel Chinese documentation many times.
Manual verification in AuthController.
Login function:

<code>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('<br>', $errors), 'error');  //我使用了laracasts/flash这个扩展包,如果你没安装,用$request->session->flash()也是一样的
        }

        return redirect('/login')
                   ->withInput();  //不使用->withErrors就不会显示红字
    }

    //验证登录代码省略...
}</code>
Copy after login

The registration function is similar.

I want to know how to replace your variables into Chinese

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template