number validation in laravel code example

Example 1: laravel validation integer

'count' => 'integer'

Example 2: numbric validate laravel

$rules = ['Fno' => 'numeric|min:2|max:5', 'Lno' => 'numeric|min:2'];

Example 3: email validation in laravel

'email' => 'required|email|unique:users,email',
//@sujay

Example 4: laravel validate integer between

'item' => 'required|integer|between:1,10',

Example 5: laravel validator make custom message

$rules = [
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required|max:250',
    ];

    $customMessages = [
        'required' => 'The :attribute field is required.'
    ];

    $this->validate($request, $rules, $customMessages);

Example 6: laravel unique validation

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */

public function store(Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}

Tags: