Answer the question
In order to leave comments, you need to log in
Why doesn't Laravel 5.3 want to show validation errors?
I am learning Laravel. Now I'm analyzing the topic with data validation and I can't display errors.
I created a request class:
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ContactRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name'=>'required',
];
}
public function messages()
{
return [
'name.required' => 'Er, you forgot your name!',
];
}
}
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests\ContactRequest;
use App\Http\Controllers\Controller;
use Validator;
class ContactController extends Controller
{
public function store(ContactRequest $request) {
return view('default.contact',['title'=>'Contacts']);
}
public function show()
{
return view('default.contact',['title'=>'Contacts']);
}
}
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
];
Route::get('/contact',['uses'=>'Admin\[email protected]','as'=>'contact']);
Route::post('/contact',['uses'=>'Admin\[email protected]']);
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="form-area">
<form method="post" action="{{ route('contact') }}">
{{ csrf_field() }}
<div class="form-group">
<input type="text" class="form-control" value="{{ old('name') }}" id="name" name="name" placeholder="Name">
</div>
<div class="form-group">
<input type="text" class="form-control" value="{{ old('email') }}" id="email" name="email" placeholder="Email">
</div>
<div class="form-group">
<input type="text" class="form-control" value="{{ old('site') }}" id="site" name="site" placeholder="site">
</div>
<div class="form-group">
<textarea class="form-control" type="textarea" name="text" id="message" placeholder="Message" maxlength="140" rows="7">{{ old('text') }}</textarea>
<span class="help-block"><p id="characterLeft" class="help-block ">You have reached the limit</p></span>
</div>
<input type="submit" id="submit" name="submit" class="btn btn-primary">
</form>
</div>
Answer the question
In order to leave comments, you need to log in
In general, thanks to Arik for help. The problem was to create a session from scratch. That is why the errors were not displayed. I solved the problem by demolishing the framework and installing from scratch.
https://github.com/laravel/framework/blob/5.3/src/...
https://github.com/laravel/framework/blob/5.3/src/...
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->messages() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question