I am currently working on a form, and have just recently added validation I have a form that the user fills out, and after it has been filled, I display validation message to the user, in a red box below the input box form. You may also like How to display form input box old value in Laravel and How to Ajax Pagination in Laravel 8.
HTML Code
<form enctype="multipart/form-data" method="post" action="{{url('admin/post/add-post/InsertPost')}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="col-md-12 col-sm-12 col-xs-12" for="first-name">Title<span class="required">*</span>
</label>
<div class="col-md-12 col-sm-12 col-xs-12">
<input type="text" name="title" value="" class="form-control col-md-7 col-xs-12">
<div style="color:#FF0000;">{{$errors->first('title')}}</div>
</div>
</div>
</form>
Route Code
Route::post('admin/post/add-post/InsertPost', [
'as' => 'admin/post/add-post/InsertPost',
'uses' => 'PostController@InsertPost'
]);
Controller Code
public function InsertPost(Request $request)
{
$this->validate($request, array(
'title' => 'required|max:255',
));
}
Error message display this code
<div style="color:#FF0000;">{{$errors->first('title')}}</div>