/* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ useIlluminate\Http\Request;
Route::get('/', function () { returnview('welcome'); });
Route::get('/input', function () { returnview(('input')); });
Route::post('/input/test', function (Request $request) { if ($request->isMethod('post')) { echo"yes"; } else { echo"no"; } });
/* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ useIlluminate\Http\Request;
Route::get('/', function () { returnview('welcome'); });
Route::get('/input', function () { returnview(('input')); });
classStoreTestPostextendsFormRequest { /** * 确定用户是否有权提出此请求。 * Determine if the user is authorized to make this request. * * @return bool */ publicfunctionauthorize() { returntrue; }
/** * 获取应用于请求的验证规则。 * Get the validation rules that apply to the request. * * @return array */ publicfunctionrules() { return [ 'test' => 'required', ]; }
/* * 为规则写入提示信息 * Write prompt information for rules */ publicfunctionmessages() { return [ 'required' => ':attribute必填', ]; }
/* * 为表单设置名称 * Set a name for the form */ publicfunctionattributes() { return [ 'test' => "测试", ]; } }
需要注意的是我们还需要修改当前的控制器,将请求改为表单请求:
1 2 3 4 5 6 7 8 9 10
/** * Store a newly created resource in storage. * * @param StoreTestPost $request * @return \Illuminate\Http\Response */ publicfunctionstore(StoreTestPost $request) { // }