If you don't see an error, that's means there's no any validation error.
VSCode shows red line because it doesn't recognize it, however as the documentation mentioned it's there in the view by default
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I am making a project on Laravel 9 and in a simple login form I added validation rules in the controller and try to show it using $errors variable in blade using @if($errors->any())
If you don't see an error, that's means there's no any validation error.
VSCode shows red line because it doesn't recognize it, however as the documentation mentioned it's there in the view by default
@MohamedTammam I tried filling up the form with a validation error but still its not showing up
@Chimpoo How are you validating? can you please show the code both the view file and the controller.
@MohamedTammam In Controller public function emplogin(request $req){
$validate = $req->validate([
'email' => 'required',
'password' => 'required|min:5',
]);
return $req->input();
}
in Blade file
@csrf @if($errors->any()) <!-- Email input -->
<div class="form-outline mb-4">
<input type="email" id="form3Example3" class="form-control form-control-lg"
placeholder="Enter a valid email address" name="email" />
<label class="form-label" for="form3Example3">Email address</label>
</div>
<!-- Password input -->
<div class="form-outline mb-3">
<input type="password" id="form3Example4" class="form-control form-control-lg"
placeholder="Enter password" name="password" />
// ..... more code below
@Chimpoo Where is the form tag?
@MohamedTammam Also I tried making a new project with the same code but in that new project in he kernel.php file I dont have \Illuminate\Session\Middleware\StartSession::class, in the global HTTP middleware stack. so I commented out this line in my original project having this errors and erros starts showing up but I have adminlogin code also on this project. After commentng out this line, that login page is now giving errors ike "Session store not set on request."
@Chimpoo Did you run composer install?
@MohamedTammam Its there Heres te whole code
<div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1">
<form action="" method="post">
@csrf
@if($errors->any())
<div>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<!-- Email input -->
<div class="form-outline mb-4">
<input type="email" id="form3Example3" class="form-control form-control-lg"
placeholder="Enter a valid email address" name="email" />
<label class="form-label" for="form3Example3">Email address</label>
</div>
<!-- Password input -->
<div class="form-outline mb-3">
<input type="password" id="form3Example4" class="form-control form-control-lg"
placeholder="Enter password" name="password" />
<label class="form-label" for="form3Example4">Password</label>
</div>
{{-- <div>
@error('password')
<span>{{$message}}</span>
@enderror
</div> --}}
<div class="d-flex justify-content-between align-items-center">
<!-- Checkbox -->
<a href="#!" class="text-body">Forgot password?</a>
</div>
<div class="text-center text-lg-start mt-4 pt-2">
<button type="submit" class="btn btn-primary btn-lg"
style="padding-left: 2.5rem; padding-right: 2.5rem;">Login</button>
<p class="small fw-bold mt-2 pt-1 mb-0">Don't have an account? <a href="{{route('reg')}}"
class="link-danger">Register</a></p>
</div>
</form>
</div>
</div>
</div>
@Chimpoo The action attribute in the form is empty, you need to add the correct URL to that.
@MohamedTammam I am using the home page with routes like
Route::get('/', [Emp_Controller::class,'emp_welcome']);
Route::post('/', [Emp_Controller::class,'emplogin']);
and in the controller
public function emp_welcome(){ return view('emp_login'); }
public function emplogin(request $req){
$validate = $req->validate([
'email' => 'required',
'password' => 'required|min:5',
]);
return $req->input();
}
@MohamedTammam Thankyou for the help. Appreciate it
It seems like \Illuminate\Session\Middleware\StartSession::class, in gobal mddleware list (which runs during every request to your application) is making this issue. After commenting out this line, The errors are showing up but then I cant make login logic and start any session
upate I cmmented out \Illuminate\Session\Middleware\StartSession::class, from 'web' in group midlewares and now everyting is fine
@Chimpoo NO, THAT IS NOT FINE.
You have the keep that middlewares for security reasons.
@MohamedTammam the one I commented out(\Illuminate\Session\Middleware\StartSession::class) is already there in gobal midleware list also which runs on every request. Is it still fine or not?
@Chimpoo Don't remove anything that comes with the default installation.
please read the docs and let laravel redirect after validation, then all will be good
You don't have $errors in your controller, the framework ensures it is created when rendering a view
Please or to participate in this conversation.