laravel请求表单验证(Laravel request form validation)

laravel请求表单验证

定义路由首先,我们假定在 routes/web.php 文件中包含如下路由:1// 显示创建博客文章表单…2Route::get(‘post/create’, ‘PostController@create’);3// 存储新的博客文章…Route::post(‘post’, ‘PostController@store’);

2,创建控制器

php artisan make:controller IndexController

namespace App\Http\Controllers;use Illuminate\Http\Request;class IndexController extends Controller{    //        public function formm(){                return view(‘formm’);            }        public function store(Request $request){                //dd($request->all());        $validatedData = $request->validate([        ‘title’ => ‘required|max:255’,        ‘body’ => ‘required’,        ]);                return ‘www.96net.com.cn’;            }    }

————————

Laravel request form validation

To define a route, we first assume that it is in routes / Web PHP file contains the following routes: 1 / / the create blog post form is displayed 2Route::get(‘post/create’, ‘ PostController@create ‘); 3 / / store new blog posts Route::post(‘post’, ‘ PostController@store ‘);

2. Create controller

php artisan make:controller IndexController

namespace App\Http\Controllers; use Illuminate\Http\Request; class IndexController extends Controller{    //        public function formm(){                return view(‘formm’);             }        public function store(Request $request){                //dd($request->all());        $validatedData = $request->validate([        ‘title’ => ‘required|max:255’,        ‘body’ => ‘required’,        ]);                return ‘www.96net.com.cn’;             }    }