{"id":3905,"date":"2020-09-11T08:13:03","date_gmt":"2020-09-11T08:13:03","guid":{"rendered":"https:\/\/programmingfields.com\/?p=3905"},"modified":"2023-09-26T04:24:22","modified_gmt":"2023-09-26T04:24:22","slug":"laravel-8-form-validation-tutorial-for-beginners","status":"publish","type":"post","link":"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/","title":{"rendered":"Laravel 8 Form Validation Tutorial For Beginners"},"content":{"rendered":"\n<p>Form validation is a client type of validation that is required in any form. Whether you are creating a <strong>contact form<\/strong>, <strong>lead form,<\/strong> or any kind of <strong>registration<\/strong>. It always required a completed and validated data. If you are taking inputs from the users, you always want that user is genuine. Also, every information must relate to the user and it should be correct. Hence, in this tutorial, I will be showing you the <strong>Laravel 8 form validation<\/strong>. I will be starting from the scratch. <\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Prerequisites\" >Prerequisites<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Create_Project_For_Laravel_8_Form_Validation\" >Create Project For Laravel 8 Form Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Create_and_Configure_Database\" >Create and Configure Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Create_a_Model_and_Migration\" >Create a Model and Migration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Add_Fillable_Data_in_User_Model\" >Add Fillable Data in User Model<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Create_a_Controller_For_Form_Validation\" >Create a Controller For Form Validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Create_View\" >Create View<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/programmingfields.com\/laravel-8-form-validation-tutorial-for-beginners\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span><strong>Prerequisites<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For creating this form validation project in Laravel 8, we will require the following tools and version.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>PHP &gt;= 7.3<\/strong><\/li><li><strong>MySQL (version &gt; 5)<\/strong><\/li><li><strong>Apache\/Nginx Server<\/strong><\/li><li><strong>VS Code Editor<\/strong><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_Project_For_Laravel_8_Form_Validation\"><\/span><strong>Create Project For Laravel 8 Form Validation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For validating a form in Laravel 8, I will create a basic registration form. Then for that form inputs, I will put the validation rules in the controller. Also, I will be displaying out the validation errors in the form. So, this is a basic overview of this project.<\/p>\n\n\n\n<p>Now, we will be creating the Laravel 8 project using the composer. So, use the terminal or command prompt and hit the below command.<\/p>\n\n\n\n<pre title=\"create-project\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">composer create-project --prefer-dist laravel\/laravel form-validation<\/code><\/pre>\n\n\n\n<p>It will take a couple of minutes to ready the setup.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"437\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/1.-Create-project-in-Laravel-8.png?resize=900%2C437&#038;ssl=1\" alt=\"Create Project in Laravel 8 for form validation\" class=\"wp-image-3907\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/1.-Create-project-in-Laravel-8.png?w=900&amp;ssl=1 900w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/1.-Create-project-in-Laravel-8.png?resize=300%2C146&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/1.-Create-project-in-Laravel-8.png?resize=768%2C373&amp;ssl=1 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><figcaption><strong>Create Project in Laravel 8<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p>When the project is ready, let&#8217;s create and configure a database for this.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/laravel-8-crud-application-tutorial-from-scratch\/\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel 8 CRUD Application Tutorial From Scratch<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_and_Configure_Database\"><\/span><strong>Create and Configure Database<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For the database, I will be using the MySQL command line. So, create a database by giving a name there.<\/p>\n\n\n\n<pre title=\"create-database\" class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">CREATE DATABASE laravel8_form_validation;<\/code><\/pre>\n\n\n\n<p>Now, we have the database ready. In the next step, we&#8217;ll connect with the Laravel 8 Form validation project.<\/p>\n\n\n\n<pre title=\".env file\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">DB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=laravel8_form_validation\nDB_USERNAME=root\nDB_PASSWORD=root<\/code><\/pre>\n\n\n\n<p>You will have to replace the <strong>DB_USERNAME <\/strong>and <strong>DB_PASSWORD<\/strong>. Then the project is good to go with the database.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/implement-yajra-datatable-in-laravel-7\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Implement Yajra DataTable in Laravel 7<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_a_Model_and_Migration\"><\/span><strong>Create a Model and Migration<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>I will be creating a form with some specific inputs. When the form validation will pass, I will be storing the value to the database table.<\/p>\n\n\n\n<p>Here, I will be using the default model and the migration available in the project. Laravel provides a model and migration for the User. So, let&#8217;s use it with some modifications in migration.<\/p>\n\n\n\n<pre title=\"create_users_table.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreateUsersTable extends Migration\n{\n    \/**\n     * Run the migrations.\n     *\n     * @return void\n     *\/\n    public function up()\n    {\n        Schema::create('users', function (Blueprint $table) {\n            $table->id();\n            $table->string('name')->nullable();\n            $table->string('email')->unique();\n            $table->string('phone')->unique();\n            $table->string('address')->nullable();\n            $table->string('password');\n            $table->rememberToken();\n            $table->timestamps();\n        });\n    }\n\n    \/**\n     * Reverse the migrations.\n     *\n     * @return void\n     *\/\n    public function down()\n    {\n        Schema::dropIfExists('users');\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>I have added some fields in the default migration file. Now, moving to the next step, and adding the fillable data in the <strong>User.php<\/strong> (model).<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/laravel-7-yajra-datatable-with-server-side-processing\/\" target=\"_blank\" rel=\"noreferrer noopener\">Laravel 7 Yajra DataTable with Server Side Processing<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_Fillable_Data_in_User_Model\"><\/span><strong>Add Fillable Data in User Model<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In Laravel 8, we have a separate folder for the models file. So, you can find the <strong>Models <\/strong>directory inside the app. Add the below fillable data there.<\/p>\n\n\n\n<pre title=\"Models\/User.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Contracts\\Auth\\MustVerifyEmail;\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Illuminate\\Notifications\\Notifiable;\n\nclass User extends Authenticatable\n{\n    use HasFactory, Notifiable;\n\n    \/**\n     * The attributes that are mass assignable.\n     *\n     * @var array\n     *\/\n    protected $fillable = [\n        'name', 'email', 'password', 'phone', 'address'\n    ];\n\n    \/**\n     * The attributes that should be hidden for arrays.\n     *\n     * @var array\n     *\/\n    protected $hidden = [\n        'password', 'remember_token',\n    ];\n\n    \/**\n     * The attributes that should be cast to native types.\n     *\n     * @var array\n     *\/\n    protected $casts = [\n        'email_verified_at' => 'datetime',\n    ];\n}\n<\/code><\/pre>\n\n\n\n<p>After specifying the fillable data, let&#8217;s migrate the table.<\/p>\n\n\n\n<pre title=\"migrate table\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">php artisan migrate<\/code><\/pre>\n\n\n\n<p>The above command will migrate all the migration file in the database.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"899\" height=\"189\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/2.-Migrate-tables.png?resize=899%2C189&#038;ssl=1\" alt=\"Migrate Tables in Laravel 8\" class=\"wp-image-3910\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/2.-Migrate-tables.png?w=899&amp;ssl=1 899w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/2.-Migrate-tables.png?resize=300%2C63&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/2.-Migrate-tables.png?resize=768%2C161&amp;ssl=1 768w\" sizes=\"auto, (max-width: 899px) 100vw, 899px\" \/><figcaption><strong>Migrate Tables in Laravel 8<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/crud-app-in-react-js-using-laravel-7-restful-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Create a CRUD App in React.js Using Laravel 7 RESTful API<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_a_Controller_For_Form_Validation\"><\/span><strong>Create a Controller<\/strong> <strong>For Form Validation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For handling the form validation in Laravel 8, we will require a controller. The controller will read out the inputs from the view (form). In the controller we will write the validation rules as well.<\/p>\n\n\n\n<pre title=\"create-controller\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">php artisan make:controller UserController<\/code><\/pre>\n\n\n\n<p>The above command will create a controller file named <strong>UserController.php<\/strong>.<\/p>\n\n\n\n<pre title=\"UserController.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\nnamespace App\\Http\\Controllers;\nuse Illuminate\\Http\\Request;\nuse App\\Models\\User;\n\nclass UserController extends Controller\n{\n\n    public function create() {\n        return view('registration-form');\n    }\n\n    \/\/ ----------- [ Form validate ] -----------\n    public function store(Request $request) {\n\n        $request->validate(\n            [\n                'name'              =>      'required|string|max:20',\n                'email'             =>      'required|email|unique:users,email',\n                'phone'             =>      'required|numeric|min:10',\n                'password'          =>      'required|alpha_num|min:6',\n                'confirm_password'  =>      'required|same:password',\n                'address'           =>      'required|string'\n            ]\n        );\n\n        $dataArray      =       array(\n            \"name\"          =>          $request->name,\n            \"email\"         =>          $request->email,\n            \"phone\"         =>          $request->phone,\n            \"address\"       =>          $request->address,\n            \"password\"      =>          $request->password\n        );\n\n        $user           =       User::create($dataArray);\n        if(!is_null($user)) {\n            return back()->with(\"success\", \"Success! Registration completed\");\n        }\n\n        else {\n            return back()->with(\"failed\", \"Alert! Failed to register\");\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>For the above functions, we have to create the routes in the <strong>web.php<\/strong> file. As per the update in Laravel 8, you can create the <a href=\"https:\/\/laravel.com\/docs\/8.x\/routing\" target=\"_blank\" rel=\"noreferrer noopener\">route<\/a> as showing below. Now, the controller will be imported as a namespace in the route file.<\/p>\n\n\n\n<pre title=\"web.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;?php\n\nuse App\\Http\\Controllers\\UserController;\nuse Illuminate\\Support\\Facades\\Route;\n\n\nRoute::get(\"user\", [UserController::class, 'create']);\n\nRoute::post(\"user\/create\", [UserController::class, 'store']);\n<\/code><\/pre>\n\n\n\n<p>After creating the routes, let&#8217;s create a view for getting the user inputs.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/implement-datatable-column-filter-in-laravel-7\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Implement Column Filter in Laravel 7 Yajra Datatable<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_View\"><\/span><strong>Create View<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For the registration form, we will have to create a view. So, in the <strong>resources\/views,<\/strong> we will create a <strong>registration-form.blade.php<\/strong> file.<\/p>\n\n\n\n<pre title=\"registration-form.blade.php\" class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">&lt;!doctype html>\n&lt;html lang=\"en\">\n  &lt;head>\n    &lt;title> Laravel 8 Form Validation - Programming Fields&lt;\/title>\n    &lt;meta charset=\"utf-8\">\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n    &lt;link rel=\"stylesheet\" href=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.3.1\/css\/bootstrap.min.css\" integrity=\"sha384-ggOyR0iXCbMQv3Xipma34MD+dH\/1fQ784\/j6cY\/iJTQUOhcWr7x9JvoRxT2MZw1T\" crossorigin=\"anonymous\">\n  &lt;\/head>\n  &lt;body>\n    &lt;div class=\"container mt-5\">\n        &lt;form action=\"{{url('user\/create')}}\" method=\"POST\">\n            @csrf\n            &lt;div class=\"row\">\n                &lt;div class=\"col-xl-6 m-auto\">\n                    &lt;div class=\"card shadow\">\n                        @if(Session::has('success'))\n                            &lt;div class=\"alert alert-success alert-dismissible\">\n                                &lt;button type=\"button\" class=\"close\" data-dismiss=\"alert\">\u00d7&lt;\/button>\n                                {{Session::get('success')}}\n                            &lt;\/div>\n                        @elseif(Session::has('failed'))\n                            &lt;div class=\"alert alert-danger alert-dismissible\">\n                                &lt;button type=\"button\" class=\"close\" data-dismiss=\"alert\">\u00d7&lt;\/button>\n                                {{Session::get('failed')}}\n                            &lt;\/div>\n                        @endif\n\n                        &lt;div class=\"card-header\">\n                            &lt;h4 class=\"card-title font-weight-bold\"> Laravel 8 Form Validation &lt;\/h4>\n                        &lt;\/div>\n\n                        &lt;div class=\"card-body\">\n                            &lt;div class=\"form-group\">\n                                &lt;label for=\"name\"> Name &lt;span class=\"text-danger\"> * &lt;\/span> &lt;\/label>\n                                    &lt;input type=\"text\" name=\"name\" class=\"form-control\" value=\"{{old('name')}}\" \/>\n                                    {!!$errors->first(\"name\", \"&lt;span class='text-danger'>:message&lt;\/span>\")!!}\n                            &lt;\/div>\n\n                            &lt;div class=\"form-group\">\n                                &lt;label for=\"email\"> Email &lt;span class=\"text-danger\"> * &lt;\/span> &lt;\/label>\n                                    &lt;input type=\"text\" name=\"email\" class=\"form-control\" value=\"{{old('email')}}\" \/>\n                                    {!!$errors->first(\"email\", \"&lt;span class='text-danger'>:message&lt;\/span>\")!!}\n                            &lt;\/div>\n\n                            &lt;div class=\"form-group\">\n                                &lt;label for=\"phone\"> Phone &lt;span class=\"text-danger\"> * &lt;\/span>&lt;\/label>\n                                    &lt;input type=\"text\" max=\"10\" name=\"phone\" class=\"form-control\" value=\"{{old('phone')}}\" \/>\n                                    {!!$errors->first(\"phone\", \"&lt;span class='text-danger'>:message&lt;\/span>\")!!}\n                            &lt;\/div>\n\n                            &lt;div class=\"form-group\">\n                                &lt;label for=\"password\"> Password &lt;span class=\"text-danger\"> * &lt;\/span>&lt;\/label>\n                                    &lt;input type=\"password\" name=\"password\" class=\"form-control\" value=\"{{old('password')}}\" \/>\n                                    {!!$errors->first(\"password\", \"&lt;span class='text-danger'>:message&lt;\/span>\")!!}\n                            &lt;\/div>\n\n                            &lt;div class=\"form-group\">\n                                &lt;label for=\"confirm_password\"> Confirm Password &lt;span class=\"text-danger\"> * &lt;\/span>&lt;\/label>\n                                    &lt;input type=\"password\" name=\"confirm_password\" class=\"form-control\" value=\"{{old('confirm_password')}}\" \/>\n                                    {!!$errors->first(\"confirm_password\", \"&lt;span class='text-danger'>:message&lt;\/span>\")!!}\n                            &lt;\/div>\n\n                            &lt;div class=\"form-group\">\n                                &lt;label for=\"address\"> Address &lt;span class=\"text-danger\"> * &lt;\/span>&lt;\/label>\n                                    &lt;input type=\"text\" name=\"address\" class=\"form-control\" value=\"{{old('address')}}\" \/>\n                                    {!!$errors->first(\"address\", \"&lt;span class='text-danger'>:message&lt;\/span>\")!!}\n                            &lt;\/div>\n                        &lt;\/div>\n\n                        &lt;div class=\"card-footer\">\n                            &lt;button type=\"submit\" class=\"btn btn-success\"> Register &lt;\/button>\n                        &lt;\/div>\n                    &lt;\/div>\n                &lt;\/div>\n            &lt;\/div>\n        &lt;\/form>\n    &lt;\/div>\n    &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.3.1.slim.min.js\" integrity=\"sha384-q8i\/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\" crossorigin=\"anonymous\">&lt;\/script>\n    &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/popper.js\/1.14.7\/umd\/popper.min.js\" integrity=\"sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1\" crossorigin=\"anonymous\">&lt;\/script>\n    &lt;script src=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.3.1\/js\/bootstrap.min.js\" integrity=\"sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf\/nJGzIxFDsf4x0xIM+B07jRM\" crossorigin=\"anonymous\">&lt;\/script>\n  &lt;\/body>\n&lt;\/html>\n<\/code><\/pre>\n\n\n\n<p>Here, view is ready to serve the application. So, let&#8217;s check the result.<\/p>\n\n\n\n<p>When you will submit the form without filling up any details, then you will have the following error messages.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"778\" height=\"878\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/registration-validation-errors-1.png?resize=778%2C878&#038;ssl=1\" alt=\"Laravel 8 Form Validation Errors\" class=\"wp-image-3915\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/registration-validation-errors-1.png?w=778&amp;ssl=1 778w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/registration-validation-errors-1.png?resize=266%2C300&amp;ssl=1 266w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/registration-validation-errors-1.png?resize=768%2C867&amp;ssl=1 768w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><figcaption><strong>Laravel 8 Form Validation Errors<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p>But, when you will fill up the detail as required, you will pass the validation criteria.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/programmingfields.com\/laravel-8-image-upload-with-validation\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Upload Image in Laravel 8 with Validation<\/a><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"876\" height=\"804\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/Registration-form.png?resize=876%2C804&#038;ssl=1\" alt=\"Registration Form with Filled Detail\" class=\"wp-image-3916\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/Registration-form.png?w=876&amp;ssl=1 876w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/Registration-form.png?resize=300%2C275&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/Registration-form.png?resize=768%2C705&amp;ssl=1 768w\" sizes=\"auto, (max-width: 876px) 100vw, 876px\" \/><figcaption><strong>Registration Form with Filled Detail<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p>Once the validation passed, you will get the success response on submitting the form.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"651\" src=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/3.-Registration-completed-successfully.png?resize=656%2C651&#038;ssl=1\" alt=\"Laravel 8 Form Validation Success\" class=\"wp-image-3917\" srcset=\"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/3.-Registration-completed-successfully.png?w=656&amp;ssl=1 656w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/3.-Registration-completed-successfully.png?resize=300%2C298&amp;ssl=1 300w, https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/3.-Registration-completed-successfully.png?resize=150%2C150&amp;ssl=1 150w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><figcaption><strong>Laravel 8 Form Validation Success<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This is a basic demonstration of form validation using Laravel 8. You can pass many fields as per your form. You can change the validation error message by defining the custom rules. This can help you for creating any type of form validation. If you stuck in any kind of issues in Laravel then please let me know. I will help you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Form validation is a client type of validation that is required in any form. Whether you are creating a contact form, lead form, or any kind of registration. It always required a completed and validated data. If you are taking inputs from the users, you always want that user is genuine. Also, every information must [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":3918,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2564],"tags":[454,1872,1875,1870,1874],"yst_prominent_words":[1505,134,1755,776,442,456,1318,1504,1503,888,431,1499],"class_list":{"0":"post-3905","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-laravel","8":"tag-form-validation","9":"tag-laravel-8-eloquents","10":"tag-laravel-8-form","11":"tag-laravel-8-routes","12":"tag-laravel-form-validation","13":"entry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/programmingfields.com\/wp-content\/uploads\/2020\/09\/Laravel-8-Form-Validation.png?fit=2240%2C1260&ssl=1","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts\/3905","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/comments?post=3905"}],"version-history":[{"count":1,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts\/3905\/revisions"}],"predecessor-version":[{"id":10538,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/posts\/3905\/revisions\/10538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/media\/3918"}],"wp:attachment":[{"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/media?parent=3905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/categories?post=3905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/tags?post=3905"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/programmingfields.com\/wp-json\/wp\/v2\/yst_prominent_words?post=3905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}