Answer the question
In order to leave comments, you need to log in
How to read data from session to view (Laravel)?
Good day everyone! I continue to get acquainted with Laravel, the question arose:
I try to manually authenticate the user using the attempt () method, everything works as it should, but if authorization fails, I redirect back and write an error message to the session
, it looks like this:
return redirect()->back()->with('error', 'Неверная пара логин пароль');
Answer the question
In order to leave comments, you need to log in
With validation
$user = \Auth::attempt(['email' => $request['email'], 'password' => $request['password']], true, true);
if(!$user) {
$validator->errors()->add('email', 'Incorrect username or password.');
return \Redirect::back()
->withErrors($validator)
->withInput();
}
@if ($errors->has())
@foreach ($errors->all() as $error)
{{ $error }}
@endforeach
@endif
if(Session::has('error'))
{{ Session::get('error') }}
@endif
https://laravel.ru/docs/v5/session
I did this: I created a view that is included in the main site template. In the view, I checked the session, and if it existed, I displayed it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question