du7979 2015-03-02 15:18
浏览 45
已采纳

将订阅者添加到Campaign Monitor中的多个列表

I'm trying to add a subscriber to multiple lists using a foreach loop. But the subscriber is only being added to 1 list.

So $course is sending the correct value every time. But the find method on TrainingCourse doesn't change the campaign monitor id according to what it should be. It's fetching the id for the wrong record.

Where am I going wrong?

foreach($selectedCourses as $course)
{
    $courseCMId = TrainingCourse::find($course)->first();

    $wrap = new CS_REST_Subscribers($courseCMId->campaign_monitor_id, $auth);

    $result = $wrap->add([
        'EmailAddress' => $registration->email,
        'Name'         => $registration->name,
        'Resubscribe'  => true
    ]);

    if(!$result->was_successful())
    {
        $cm['status_code'] = $result->http_status_code;
        return Redirect::to('training/register', compact('cm'))
                       ->withErrors($validator)
                       ->withInput(Input::except('password', 'password_confirmation'));
    }
}
  • 写回答

1条回答 默认 最新

  • douhun7609 2015-03-02 17:01
    关注

    Changing the line:

    $courseCMId = TrainingCourse::find($course)->first();
    

    to:

    $courseCMId = DB::table('training_courses')->where('id', $course)->first();
    

    Solved my problem

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

报告相同问题?