duangong0690 2018-01-03 14:49
浏览 82
已采纳

App \ Http \ Controllers \ CustomerController :: postOptOut()缺少参数1

I'm looking for some advice as to how I might clean up these two methods and resolve this error? Right now, the getOptOut() is making a GET request to the API to obtain an email_token and returning the view and postOptOut() is making a POST request, with the email_token from the GET, and allowing a "customer" to opt out of the mailing list and then redirecting to customer home.

public function getOptOut(EmailOptingRequest $request)
{

    $customer = Customer::find(Auth::id());
    $email = $customer['attributes']['Email'];
    $token = "9asdfj48asdj48adja4r8";

    $client = new Client();

    $res = $client->request('GET', 
    'https://www.example.com/api/Services/Email/Opting', [
        'headers' => [
            'Accept' => 'application/json',
            'Authorization' => 'Bearer ' . $token
        ],
        'email' => $email,
        'http_errors' => false // add this to return errors in json
    ]);

    $emailToken = json_decode($res->getBody()->getContents(), true);
    $this->postOptOut($emailToken);

    return view('customer.email-opting', array(
        'customer' => $customer,
        'email' => $email,
        'token' => $token,
        'client' => $client,
        'res' => $res,
        'emailToken' => $emailToken
    ));
}

public function postOptOut($emailToken)
{
    $customer = Customer::find(Auth::id());
    $email_token = $emailToken[0]['token'];

    $client = new Client();

    $res = $client->request('POST', 'https://www.example.com/api/Services/Email/Opting', [
        'email_token' => $email_token,
        'category' => 'promotional',
        'status' => false
    ]);

    return view('customer.show', array(
        'customer' => $customer,
        'email_token' => $email_token,
        'client' => $client,
        'res' => $res ))
        ->with('success', 'You were removed from our mailing list.');
}

And my routes:

Route::get(   'customer/email-opting', 'CustomerController@getOptOut');
Route::post(  'customer/post-opt-out', 'CustomerController@postOptOut');

The hard coded token is temporary. I'm running into issues with the timing of the GET and POST calls and when the views are returning. Thanks!

  • 写回答

1条回答 默认 最新

  • douguai4653 2018-01-03 14:51
    关注
    public function postOptOut(Request $request)
    {
        $customer = Customer::find(Auth::id());
        $email_token = $request->emailToken[0]['token']; // this way you will get token
    
        $client = new Client();
    
        $res = $client->request('POST', 'https://www.example.com/api/Services/Email/Opting', [
            'email_token' => $email_token,
            'category' => 'promotional',
            'status' => false
        ]);
    
        return view('customer.show', array(
            'customer' => $customer,
            'email_token' => $email_token,
            'client' => $client,
            'res' => $res ))
            ->with('success', 'You were removed from our mailing list.');
    }
    

    Try this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用