laravel请求表单验证
定义路由
首先,我们假定在 routes/web.php 文件中包含如下路由:
1
// 显示创建博客文章表单...
2
Route::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';
}
}