Using the latest Laravel 5.7.8 and what worked in Laravel 5.6.3 might not be applicable in my case.
I'm trying to create a Contact form validation (required ALERT/SUCCESS messages)
contactUS.blade.php
@extends('layout.app')
@section('content')
<div id="page">
<div id="publish">
<div class="frameterms">
<h1>Contact</h1>
<script src='https://www.google.com/recaptcha/api.js'></script>
@if(Session::has('success'))
<div class="notify yellow" style="display:block;">
{{ Session::get('success') }}
</div>
@endif
{!! Form::open(['route'=>'contactus.store']) !!}
<div class="row">
<label>Name<span class="asterix">*</span></label>
</div>
<div class="row {{ $errors->has('name') ? 'has-error' : '' }}">
{!! Form::text('name', old('name'), ['class'=>'row', 'placeholder'=>'Enter Name']) !!}
<span class="text-danger">{{ $errors->first('name') }}</span>
</div>
<div class="row {{ $errors->has('email') ? 'has-error' : '' }}">
<label>Email<span class="asterix">*</span></label>
{!! Form::text('email', old('email'), ['class'=>'row', 'placeholder'=>'Enter Email']) !!}
<span class="text-danger">{{ $errors->first('email') }}</span>
</div>
<div class="row {{ $errors->has('message') ? 'has-error' : '' }}">
<label>Subject<span class="asterix">*</span></label>
<div class="selector">
<div class="selector1">
{!! Form::select('subject', array(
'Select subject...' => 'Select subject...',
'Web' => 'Web development',
'Marketing' => 'Marketing',
'App' => 'App development',
'Advertising and Promotion' => 'Advertising and Promotion',
'Other' => 'Other') ) !!}</div>
<div>
<span class="text-danger">{{ $errors->first('message') }}</span>
</div>
<div class="row {{ $errors->has('message') ? 'has-error' : '' }}">
<label>Message<span class="asterix">*</span></label>
{!! Form::textarea('message', old('message'), ['class'=>'row', 'placeholder'=>'Enter Message']) !!}
<span class="text-danger">{{ $errors->first('message') }}</span>
</div>
<div class="row">
<small class="required"><span class="asterix">*</span> Required fields</small>
</div>
<div class="form-group {{ $errors->has('g-recaptcha-response') ? ' has-error' : '' }}">
<div class="col-md-6 pull-center">
{!! app('captcha')->display() !!}
@if ($errors->has('g-recaptcha-response'))
<span class="help-block">
<strong>{{ $errors->first('g-recaptcha-response') }}</strong>
</span>
@endif
</div>
</div>
<div class="rowbutton">
<input onclick="$('.loader').show(); $(this).hide();" type="submit" value="Send message">
<div class="loader" style="display:none;"></div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection
ContactUSController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\ContactUS;
use Illuminate\Support\Facades\Input;
use Validator;
use Redirect;
class ContactUSController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function contactUS()
{
return view('pages.contactUS');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function contactUSPost(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'message' => 'required',
'g-recaptcha-response' => 'required|captcha'
]);
ContactUS::create($request->all());
return back()->with('success', 'Thanks for contacting us!');
return redirect()->back();
}
}
web.php
Route::get('contact', 'ContactUSController@contactUS');
Route::post('contact', ['as'=>'contactus.store','uses'=>'ContactUSController@contactUSPost']);
When I fill out the contact form, it adds a post to the SQL database on the backend. And when it fails, it goes back to the contact form view.
The problem is that the validator errors and SUCCESS message don't show up in the view even though I have coded in.
Does anyone know how to solve this problem? Is there any workaround? Any suggestion will be appreciated. Thank you in advance.
This is the picture from Laravel 5.6.3 project and required fields are working:
This is a picture from Laravel 5.7.8 project and required fields are NOT working:

