在laravel中将数组转换为变量时出现错误

时间:2019-03-13 07:24:06

标签: laravel

将多个复选框($ request-> courses)转换为变量(checkbox1)时遇到问题。因为我需要向数据库中插入一个数组。

public function store(Request $request) {

  $customer = new prospect;
  $customer->ProspectName = $request->ProspectName;
  $customer->NicNumber = $request->NicNumber;
  $customer->ContactNumber = $request->ContactNumber;
  $customer->ContactAddress = $request->ContactAddress;
  $customer->Comments = $request->Comments;
  $customer->ReferredThrough = $request->ReferredThrough;

  $checkbox1 = $request->courses; //courses is an array from form
  $chk = "";
  foreach ($checkbox1 as $chk1) {
    $chk .= $chk1 . ",";
  }
  $customer->IntrestedCourses = $chk;


  if ($customer->save()) {
    echo 'saved successfully';
  } else {
    echo 'error';
  }
}

但是我出错了!

0 个答案:

没有答案