Laravel 5 auth控制器中的flash消息

Laravel 5 auth控制器中的flash消息,laravel-5,Laravel 5,我正在寻找更好的解决方案,在登录/注销/注册后显示flash消息。这些方法通过特征AuthenticateSandRegisterSuser存储在AuthController中。我的第二个条件是不编辑AuthenticateSandRegisterSuser 实际上我的黑客是在下面,但我不高兴。 你有更好的主意吗 app/http/controllers/auth/authcontroller.php public function postLoginwithFlash(Request $req

我正在寻找更好的解决方案,在登录/注销/注册后显示flash消息。这些方法通过特征AuthenticateSandRegisterSuser存储在AuthController中。我的第二个条件是不编辑AuthenticateSandRegisterSuser

实际上我的黑客是在下面,但我不高兴。 你有更好的主意吗

app/http/controllers/auth/authcontroller.php

public function postLoginwithFlash(Request $request)
{
return $this->postLogin($request)->with('flash_message','You are logged');
}
Route::post('login', ['as' => 'login', 'uses' => 'Auth\AuthController@postLoginWithFlash']);
routes.php

public function postLoginwithFlash(Request $request)
{
return $this->postLogin($request)->with('flash_message','You are logged');
}
Route::post('login', ['as' => 'login', 'uses' => 'Auth\AuthController@postLoginWithFlash']);
视图ofc

@if (Session::has('flash_message'))
{{ Session::get('flash_message') }}
@endif

没有“本地”的方法来做这件事。无论哪种方式,您都必须更改/编辑路线

要么在routes.php中实现所有内容,要么按照您已经提出的方式实现——在AuthController中创建一个新方法。本质上,这是一回事

但是,我建议您进行适当的手动检查,而不是返回postLogin(),例如:


这样,您可以向成功和错误案例中添加不同的flash消息,而无论结果如何,您建议的代码都将显示相同的消息。

您可以编辑语言文件/resources/lang/en/auth.php,然后更改此行

'failed' => 'Your custom login error message',