In this tutorial learn how to validation in controller all variables in laravel. laravel validation working using the validator function.
Defining The Routes
Defining The Routes
First, let's assume we have the following routes defined in our
routes/web.php
file:Route::get('post/create', 'UserController@create');
Route::post('post', 'UserController@store');
Creating The Controller
Next, let's take a look at a simple controller that handles these routes. We'll leave the
store
method empty for now:<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Show the form to create a new blog post.
*
* @return Response
*/
public function create()
{
return view('post.create');
}
/**
* Store a new blog post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
// Validate and store the blog post...
}
}
validation define above the class package in controlleruse Validator;
public function store(Request $request) {
//print_r($request->all());$validator = Validator::make($request->all(), ['email' => 'email','vat_number' => 'max:13','password' => 'min:6|required_with:password_confirmation|same:password_confirmation','password_confirmation' => 'min:6']);if ($validator->fails()) {return redirect('emaillist/create')->withErrors($validator)->withInput();}}
No comments:
Post a Comment