I am new to Laravel and was trying to validate inputs to a form. I use blade templating engine. The validation works because, it doesn't insert data into the db but the errors don't show up either. Here is what I did for my SignUp form:
@section('content')
@if(count($errors)>0)
<div class="row">
<div class="col-md-6">
<ul>
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
</div>
</div>
@endif
<div class="row">
<div class="col-md-6">
<h3>Sign Up</h3>
<form action="{{ route('signup') }}" method="post">
<div class="form-group">
<label for="username">Username :</label>
<input class="form-control" type="text" name="username" id="username" >
</div>
<div class="form-group">
<label for="name">Name :</label>
<input class="form-control" type="text" name="name" id="name">
</div>
<div class="form-group">
<label for="email">E-Mail :</label>
<input class="form-control" type="text" name="email" id="email">
</div>
<div class="form-group">
<label for="password">Password :</label>
<input class="form-control" type="password" name="password" id="password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
</div>
@endsection
Also here is my login where I validate the fields and make the user logged in:
public function postSignUp(Request $request)
{
$this->validate($request, [
'username' => 'required|unique:users|max:20|min:2',
'name' => 'required|max:30|min:2',
'email' => 'required|email|unique:users|max:50|min:5',
'password' => 'required|min:4'
]);
$username = $request["username"];
$name = $request["name"];
$email = $request["email"];
$password = bcrypt($request["password"]);
$user = new User();
$user->username = $username;
$user->name = $name;
$user->email = $email;
$user->password = $password;
$user->save();
Auth::login($user);
return redirect()->route('dashboard');
}
For some reason, when I do a already taken username or wrong email and click on Submit button, it redirects me back to the signup page which is the expected functionality but it doesn't show the errors at all.
EDIT: Here is my route.php:
Route::group(['middleware' => ['web']], function (){
Route::get('/', function () {
return view('welcome');
});
Route::post('/signup', [
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
Route::post('/signin', [
'uses' => 'UserController@postSignIn',
'as' => 'signin'
]);
Route::get('/dashboard', [
'uses' => 'UserController@getDashboard',
'as' => 'dashboard'
]);
});