What if you try the following
return back()->withErrors($validator)->withInput();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I've been struggling with this for a few hours and if anyone knew what was happening. I'm using Laravel 9 with Sail on Ubuntu 20.04.1. Currently, when updating the blurb fails because its too long, the errors do exist in $validator->errors() - ive checked with dd. The only problem is that the $errors dont exist in the view. Furthermore, when I went back to check out my register controller, $errors stopped existing there too - leading me to believe that this is related to the session and not how im handling validation. Here's my controller code:
$validator = Validator::make($request->all(), [
"blurbText" => "required|max:150"
]);
if ($validator->fails()) {
//dd($validator->errors());
return back()->withErrors($validator->errors())->withInput();
}
Auth::user()->blurb = $request->input("blurbText");
Auth::user()->save();
return back();
Along with my view code (blade):
<div class="card-body">
<form method="POST">
@csrf
<div class="form-floating">
<textarea type="text" class="form-control @error('blurbText') is-invalid @enderror" id="blurbText" name="blurbText" style="height: 100px">{{ Auth::user()->blurb }}</textarea>
</div>
<input type="hidden" id="updateMethod" name="updateMethod" value="blurb">
<i class="text-muted">max: 150 chars</i><br>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
<button class="btn btn-primary" type="submit">update</button>
</form>
</div>
But unfortunately, $errors->all() never exists purely because no $errors are available on the view. I've checked with dd there too. Not to mention the fact that most stackoverflow etc posts relating to this seem to be related to updates in Laravel 5. I tried switching from file to redis and using artisan clear:cache, but it didn't fix anything. If anyone could help I'd appreciate it. Thanks.
Hi, just fixed the problem and I'm posting this here in case anyone has this issue. I managed to fix it by upgrading my project to Laravel 10, but I'm quite certain that the issue was just something was broken with Sail so try and restart your project with a new Sail.
Please or to participate in this conversation.