Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

NoTimeForCaution's avatar

Register Controller return back upon Validator fail

I've added a few additional input fields to the default registration. When a user sends the request I capture their employee number and verify that it exists in the database. I'm trying to return back to the /register page if it does not (null).

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

$pilot = Pilot::where('emp', request('emp'))->get()->sortBy('month')->last();
        if($pilot === null)
        {
            flash('EMPLOYEE VALIDATION FAILED.');
            return back();
        }
Call to undefined method Illuminate\Http\RedirectResponse::validate()

Also tried:

return redirect('/register');

Only thing that works is return abort(403).

0 likes
2 replies
frezno's avatar

you don't get an error with this query, @dawgonking ?

i'd try

$pilot = Pilot::where('emp', request('emp'))
    ->orderBy('month')
    ->latest()
    ->limit(1)
    ->get();

Please or to participate in this conversation.