Randeep Singh Randeep Singh - 2 years ago 107
PHP Question

Laravel 5.2 Validation Error not appearing in blade

I want to show validation Error in View page while user giving wrong input. It's Ok that it's not saving anything in database while a user giving wrong input. But there is no error message in user view page. If anyone find the error, please help me out.

Here is the controller:

public function saveUser(Request $request){
'name' => 'required|max:120',
'email' => 'required|email|unique:users',
'phone' => 'required|min:11|numeric',

$user = new User();
$user->name= $request->Input(['name']);
$user->email= $request->Input(['email']);
$user->phone= $request->Input(['phone']);
$user->date = date('Y-m-d');
$user->completed_status = '0';
return redirect('success');

Here is the route:

Route::group(['middleware' => 'web'], function () {

Route::get('/', function () {
return view('index');

'uses' => 'AppController@saveUser',

Here is the blade view page:

Create User
<div class="container" >

<h3> Student Register </h3>

{!! Form::open(array('route' => 'saveUser','class'=>'form-horizontal','method'=>'POST')) !!}
{!! Form::token(); !!}
{!! csrf_field() ; !!}

<div class="form-group">
<input type="text" name="name" class="form-control" required placeholder="Name">

<div class="form-group">
<input type="email" name="email" class="form-control" required placeholder="email">

<div class="form-group">
<label>Phone Number</label>
<input type="text" name="phone" class="form-control" required placeholder="phone">

<div class="form-group">
<label for="">Class</label>
<select class="form-control input-sm" name="course_id" >
@foreach($input as $row)
<option value="{{$row->id}}">{{$row->name}}</option>

<button type="submit" class="btn btn-default">Submit</button>
{!! Form::close() !!}


And here is the error-message block:

@if(count($errors) > 0)
<div class="row">
<div class="col-md-4 col-md-offset-4 error">
@foreach($errors->all() as $error)
<div class="row">
<div class="col-md-4 col-md--offset-4 success">


Answer Source

Try to remove web middleware if you're using 5.2.27 or higher. The thing is now Laravel automatically applies web middleware to all routes inside routes.php and if you're trying to add it manually you can get errors.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download