I am trying to return errors back to my view, this is part of my controller TestcategoryController
$rules =array(
\'name\' => \'required\'
You need to use it like this:
{{ $errors->getBag('default')->first('name') }}
Probably another issue would be with $errors not being saved to Session variable $errors and nothing being shown in the view.
Here is an example of the same issue: http://laravel.io/forum/03-28-2016-errors-variable-empty-after-failed-validation
For me the solution defined in the above link worked.
Solution: Is in app\Http\Kernel.php
Move
\Illuminate\Session\Middleware\StartSession::class,
from $middlewareGroups to $middleware
Before
After
Route::group(['middleware' => ['web']], function() {
Route::get('/home', 'HomeController@index')->name('home');
});
Add middleware, and resolved..
If you get nothing in your case, than it means you have overridden your $errors object with something else or with empty object - check your code and data you pass to the views. Your code is perfectly valid and works good - I've tested it locally. Maybe, you passed empty $errors object to your subview, but in other views the correct object is used.
I was having the same problem with Laravel 8.0
The only way I could solve this was by entering the error bags layer by layer until I got to the messages manually:
@if (count($errors->getBags()))
<div class="alert alert-danger">
<ul>
@foreach ($errors->getBags() as $bag)
@foreach ($bag->getMessages() as $messages)
@foreach ($messages as $message)
<li>{{ $message }}</li>
@endforeach
@endforeach
@endforeach
</ul>
</div>
@endif