【问题标题】:Getting this error; "The Response content must be a string or object implementing __toString(), "boolean" given."收到此错误; “响应内容必须是实现 __toString() 的字符串或对象,给定的“布尔值”。”
【发布时间】:2019-10-02 02:00:05
【问题描述】:

基本上,当我尝试为我的数据库创建一个新条目时,我会收到此错误。我几乎所有其他关于此事的文章都是真实的,但还没有找到错误/问题。我的代码就是这样;

$userId = DB::table(\Config::get('constants.DB_MAIN_DATABASE') . '.users')->insertGetId(
[
  'email' => $input['email'],
  'name' => $input['name'],
  'mobile_no' => $input['mobile_no'],
  'interest' => $input['interest'] ? implode(',', $input['interest']) : null,
  'interest_other' => $input['interest_other'] ? $input['interest_other'] : null,
  'password' => bcrypt($input['password']),
  'verified' => 0,
  'admin' => 0,
  'token' => str_random(30),
  'created_at' => date('Y-m-d H:i:s'),
]);
dd($userId);

请注意,我什至无法访问我的 dd。值是这样的;

$input['email'] = "Prawn@abc.com"
$input['name'] = "Udh N"
$input['mobile_no'] = "0123456789"
$input['interest'] = "1"
$input['interest_other'] = "2"
$input['password'] = "password"

这里有什么问题吗?

【问题讨论】:

  • 发生在哪一行?
  • 它说 Response.php 第 399 行?但我什至没有对此添加回复..
  • 你能提供一个堆栈跟踪吗?
  • 如果你注释掉这两行,你会得到同样的错误吗?
  • 一旦我将'interest' 和'interest_other' 设置为空,它就起作用了。但如果我使用上面显示的方式,它就不起作用。奇数...

标签: laravel


【解决方案1】:

您正在对字符串使用内爆。

implode(',', $input['interest'])

要修复此错误,请将您的字符串设置为数组

implode(',', [$input['interest']])

【讨论】:

  • 谢谢!这行得通,但我仍然不明白为什么错误如上所述,而不是说明类型不匹配或其他内容。
猜你喜欢
  • 2017-08-17
  • 2013-07-21
  • 2019-03-17
  • 1970-01-01
  • 1970-01-01
  • 2018-06-04
  • 1970-01-01
相关资源
最近更新 更多