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,只能赋值到一个变量,再用数组的方式才能读出东西来,是要引用个什么东西?

问题描述可能不清晰,要是有大佬有时间,可以帮忙QQ远程查看的话,愿意付费解决

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2

我帮你理一理,按操作步骤:

  1. GET,返回一个 view,是一个页面,里面填写手机号,点击发送验证码,到第 2 步;
  2. POST,生成验证码,存入缓存,返回一个 redirect,到第 3 步;
  3. GET,返回一个 view,是一个页面,里面填写验证码,点击验证,到第 4 步;
  4. POST,验证验证码,返回一个 redirect验证通过 ? 通过后的页面 : 失败后的页面(可以是第 3 步)
4年前 评论
wongvio (楼主) 4年前

第一步(get):

Route::get('/users/create', 'UsersController@create')->name('users.create');
public function create()
    {
        return view("mobile.auth.member-login");
    }

第二步(post):

Route::post('/sendverificode', 'VerificationCodesController@sendVerifiCode')->name('sendVerifiCode');
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();
        //     session()->flash('danger', '很抱歉,您的邮箱和密码不匹配');
        //     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);

        $verifiArray = \Cache::get($key);

        return redirect()->route('verifiCodeInput',$verifiArray['verification_key']);
    }

第三步(get)

Route::get('/verificodeinput', 'VerificationCodesController@verifiCodeInput')->name('verifiCodeInput');
public function verifiCodeInput (){
        return  view('mobile.auth.member-login-verificationCode');
    }

第四步(post),出问题了,第二步的值,在第三步里不显示。。。。

4年前 评论
largezhou 4年前
wongvio (作者) (楼主) 4年前
largezhou 4年前
wongvio (作者) (楼主) 4年前
____ 4年前
wongvio (作者) (楼主) 4年前
wongvio (作者) (楼主) 4年前
____ 4年前
wongvio (作者) (楼主) 4年前
____ 4年前
wongvio (作者) (楼主) 4年前
____ 4年前
wongvio (作者) (楼主) 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!