Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

Jquery Ajax Laravel 5.8 Form Validation

Today, We want to share with you Jquery Ajax Laravel 5.8 Form Validation.In this post we will show you Laravel 5.8 Form Validation Tutorial With Example, hear for Jquery Ajax Form Validation with Laravel 5.8 we will give you demo and example for implement.In this post, we will learn about Simple Laravel 5.8 Form Validation Using Jquery with an example.

Jquery Ajax Laravel 5.8 Form Validation

There are the Following The simple About Jquery Ajax Laravel 5.8 Form Validation Full Information With Example and source code.

  Angular 6 applications - Insert, Fetch , Edit - update , Delete Operations

As I will cover this Post with live Working example to develop Form Validation With Laravel 5.8, so the Laravel 5.8 form validation example is following below.

Step 1: Define a Laravel 5.8 Routes:

routes/web.php

Route::get('product/create', '[email protected]');

Route::post('product/create', '[email protected]');

Step 2: Create Laravel 5.8 ProductController:

Create ProductController: app/Http/Controllers/ProductController.php

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Product;
  
class ProductController extends Controller
{
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('createProduct');
    }
  
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
                'name' => 'required',
                'p_info' => 'required|min:5',
                'types' => 'required|unique:products'
            ], [
                'name.required' => 'Name is required',
                'p_info.required' => 'product info is required'
            ]);
   
        $input = request()->all();
        $input['p_info'] = bcrypt($input['p_info']);
        $product = Product::create($input);
    
        return back()->with('success', 'Product created successfully.');
    }
}

Step 3: Make a Laravel 5.8 Blade File:

resources/views/createProduct.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Simple Step By Step Laravel 5.8 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="container">
  
        <h1>pakainfo.com - Laravel 5.8 form validation 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="form-group">
                <label>product Name:</label>
                <input type="text" name="name" class="form-control" placeholder="product Name">
                @if ($errors->has('name'))
                    <span class="text-danger">{{ $errors->first('name') }}</span>
                @endif
            </div>
   
            <div class="form-group">
                <label>Product Info:</label>
                <input type="text" name="p_info" class="form-control" placeholder="Product Info">
                @if ($errors->has('p_info'))
                    <span class="text-danger">{{ $errors->first('p_info') }}</span>
                @endif
            </div>
    
            <div class="form-group">
                <strong>types:</strong>
                <input type="text" name="types" class="form-control" placeholder="types">
                @if ($errors->has('types'))
                    <span class="text-danger">{{ $errors->first('types') }}</span>
                @endif
            </div>
   
            <div class="form-group">
                <button class="btn btn-success btn-submit">Submit</button>
            </div>
        </form>
    </div>
</body>
</html>

Angular 6 CRUD Operations Application Tutorials

Read :

  Angular4 routing removes hash problem

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Jquery Ajax Laravel 5.8 Form Validation.
I would like to have feedback on my 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.

Leave a Reply

avatar
  Subscribe  
Notify of