post 还是 get 是个要疯的问题
我在写一个短信发布的页面,首先是用户提交电话号码,然后点击提交的时候,我就:
public function sendVerifiCode(VerificationCodeRequest $request, EasySms $easysms)
{
$cellphone = $request -> cellphone;
$code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
// try{
// $request = $easySms->send($phone, [
// 'template' => config('easysms.gateways.aliyun.templates.register'),
// 'data' => [
// 'code' => $code
// ],
// ]);
// } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
// $message = $exception->getException('aliyun')->getMessage();
// abort(500, $message ?: '短信发送异常');
// }
$key = 'verificationCode_'.Str::random(15);
$expiredAt = now() -> addMinutes(5);
//缓存验证码5分钟过期(->toDateTimeString())。
\Cache::put($key, ['cellphone' => $cellphone, 'verification_code' => $code, 'verification_key' => $key], $expiredAt);
return view('mobile.auth.member-login-verificationCode',['key'=>$key]);
}
然后,再下一个页面输入收到的验证码,然后一系列判断:
public function verifiCode(UserRequest $request) {
$verifyData = \Cache::get($request->verification_key);
.
.
.
}
路由文件:
.
.
.
//发送验证码
Route::post('/sendverificode', 'VerificationCodesController@sendVerifiCode')->name('sendVerifiCode');
//验证验证码
Route::post('/verifiCode', 'VerificationCodesController@verifiCode')->name('verifiCode');
.
.
.
然后我有3个问题:
1、页面跳转的时候,什么时候用return view('xxx') ,什么时候用 return redirec()->route('xxx')啊?
2、当我第二步提交验证码的时候,用post方式,系统会提示我get方式不能用,我换get,它又提示我post方式不能用,总之就是不能用,而且提示的错误信息和我用的提交方式相反。
3、\Cache::get($request->verification_key);
这个写法是我在教程里学的,但是我发现好像没有用,这种取值明明存在的值取出来是null
,只能赋值到一个变量,再用数组的方式才能读出东西来,是要引用个什么东西?
推荐文章: