Today, We want to share with you Simple Laravel Form Validation Example.In this post we will show you form validations in laravel 7/6, hear for laravel 7/6 form validations example we will give you demo and example for implement.In this post, we will learn about form validations with error message in laravel 7/6 with an example.Blogs – Pakainfo.com
Simple Laravel Form Validation Example
There are the Following The simple About Simple Laravel Form Validations Example Full Information With Example and Pakainfo.com source code.
As I will cover this Post with live Working example to develop simple form validations laravel 7/6, so the some major files and Directory structures for this example is following below.Free Download Example – Pakainfo.com
Step 1: Define a Laravel Routes:
routes/web.php
Route::get('product/create', '[email protected]'); Route::post('product/create', '[email protected]');
Step 2: Create ProductController:
app/Http/Controllers/ProductController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Product; class ProductController extends Controller { public function create() { return view('createProduct'); } public function store(Request $request) { $request->validate([ 'name' => 'required', 'password' => 'required|min:5', 'email' => 'required|email|unique:products' ], [ 'name.required' => 'Name is required', 'password.required' => 'Password is required' ]); $input = request()->all(); $input['password'] = bcrypt($input['password']); $product = Product::create($input); return back()->with('success', 'Product created successfully.'); } }
Step 3: Create :Laravel Blade File:
resources/views/createProduct.blade.php
<!DOCTYPE html> <html> <head> <title>pakainfo.com - Laravel 7/6 form validation example</title> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="pakainfo container"> <h1>pakainfo.com - Laravel 7/6 form validations example</h1> @if(Session::has('success')) <div class="alert alert-success"> {{ Session::get('success') }} @php Session::forget('success'); @endphp </div> @endif <form method="POST" action="{{ url('product/create') }}"> {{ csrf_field() }} <div class="pakainfo form-group"> <label>Name:</label> <input type="text" name="name" class="form-control" placeholder="Name"> @if ($errors->has('name')) <span class="text-danger">{{ $errors->first('name') }}</span> @endif </div> <div class="form-group"> <label>Password:</label> <input type="password" name="password" class="pakainfo form-control" placeholder="Password"> @if ($errors->has('password')) <span class="text-danger">{{ $errors->first('password') }}</span> @endif </div> <div class="pakainfo form-group"> <strong>Email:</strong> <input type="text" name="email" class="pakainfo form-control" placeholder="Email"> @if ($errors->has('email')) <span class="text-danger">{{ $errors->first('email') }}</span> @endif </div> <div class="pakainfo form-group"> <button class="pakainfo btn btn-success btn-submit">Submit</button> </div> </form> </div> </body> </html>
Our customers made these Tricks for improving – Pakainfo.com System.
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Simple Laravel Form Validations Example.
I would like to have feedback on my My Blog pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.