YouTube Icon

Code Playground.

How to display form input box error message in Laravel

CFG

How to display form input box error message in Laravel

I am currently working on a form and recently added validation, I have a form filled out by the user and after it has been filled out, I show the user's validation message in a red box below the input box form.

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>




CFG