How can i append the $errors->all() array? Like a custom error message... Searched on the internet but i did not find anything.
In my view:
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
My controller:
<?php
namespace App\Http\Controllers\Admin;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
/**
* @param Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|email|exists:users,email',
'password' => 'required',
]);
if ($user = Auth::attempt([
'email' => $request->email,
'password' => $request->password
])) {
/** @var $user User */
if ($user->isAdmin()) {
return redirect()
->route('admin.dashboard');
}
}
// wrong email or password
return redirect('/admin/login');
}
}