Error message through middleware Laravel

0

I'm trying to pass an error msg through a middleware. If you use $ errors-> all () the error appears, but how do you use $ errors-> has ('active')? Or would it be easier to pass this middleware message? Another question is how to customize the email error for example?

Middleware:

namespace Ecommerce\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class CheckStatus
{
/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)
{
    if(Auth::user()->active != 'yes') {
        Auth::logout();
        return redirect('/login')->withErrors('Usuário precisa de aprovação');
    }

    return $next($request);
}
}

View Login:

<div class="form-group ">
    <div class="col-xs-12">
        <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus placeholder="Email">
    </div>
        @if ($errors->has('email'))
            <span class="help-block">
                <strong>{{ $errors->first('email') }}</strong>
            </span>
        @endif
        @if ($errors->has('active'))
            <span class="help-block">
                <strong>{{ $errors->first('active') }}</strong>
            </span>
        @endif
</div>
    
asked by anonymous 13.05.2017 / 18:10

1 answer

2

You are only passing a message without specifying the error name. try this:

->withErrors(['active'=>'Usuário precisa de aprovação']);
    
14.05.2017 / 06:50