I've grouped certain routes that require the user to be logged in before they perform some action.
Route::group(['middleware' => 'auth'], function() {
Route::get('/posts/create', 'PostController@create');
});
Now when the user visits this url, he'll be redirected to the login page if the user is not logged in. But I want to display a custom error message saying you've to be logged in to perform this action in an error block.
Where can I pass the custom message to the login view before redirecting?
Note: I know it's obvious that if the user lands on the create post
page with a login form, it indicates that the user should login. Still, that error form is required
.
When you're redirecting add with()
clause to flash a message to the session:
return redirect()->with('message', 'You've to be logged in to perform this action');
In 5.2 you may want to override one of the login related methods (it depends on what you're trying to achieve) in the Auth\\AuthController.php
. In 5.3 do the same in the Auth\\LoginController.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.