php - Response 内容必须是实现 __toString() 的字符串或对象,移动到 psql 后给出的 "boolean"

标签 php mysql laravel laravel-5 psql

当我将我的 Laravel 应用程序从 MySQL 移动到 pSQL 时。我一直收到这个错误。

The Response content must be a string or object implementing __toString(), "boolean" given.

我有一个 API 可以返回我的促销事件

http://localhost:8888/api/promotion/1

public function id($id){
    $promotion = Promotion::find($id);
    dd($promotion); //I got something here
    return $promotion;
}

它曾经返回我的促销,现在它返回一个错误。


dd($promotion);

I got 

Promotion {#410 ▼
  #table: "promotions"
  #connection: null
  #primaryKey: "id"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: array:16 [▼
    "id" => 1
    "cpe_mac" => "000D6721A5EE"
    "name" => "qwrqwer"
    "type" => "img_path"
    "status" => "Active"
    "heading_text" => "qwerq"
    "body_text" => "werqwerqw"
    "img" => stream resource @244 ▶}
    "img_path" => "/images/promotion/1/promotion.png"
    "video_url" => ""
    "video_path" => ""
    "account_id" => 1001
    "img_url" => ""
    "footer_text" => "qwerqwerre"
    "created_at" => "2016-08-04 10:53:57"
    "updated_at" => "2016-08-04 10:53:59"
  ]
  #original: array:16 [▶]
  #relations: []
  #hidden: []
  #visible: []
  #appends: []
  #fillable: []
  #guarded: array:1 [▶]
  #dates: []
  #dateFormat: null
  #casts: []
  #touches: []
  #observables: []
  #with: []
  #morphClass: null
  +exists: true
  +wasRecentlyCreated: false
}

内容

enter image description here

__ 对此的任何提示/建议将是一个巨大的帮助!

最佳答案

您的响应必须返回某种Response 对象。您不能只返回一个对象。

所以把它改成这样:

return Response::json($promotion);

或者我最喜欢的使用辅助函数:

return response()->json($promotion);

如果返回响应不起作用,则可能是某种编码问题。参见这篇文章:The Response content must be a string or object implementing __toString(), \"boolean\" given."

关于php - Response 内容必须是实现 __toString() 的字符串或对象,移动到 psql 后给出的 "boolean",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38770871/

相关文章:

php - 将变量传递给 php 模态

mysql - 在 MySQL 中存储 UUID v4

mysql - SQL 中间表具有 column = max(column)

php - Laravel 5.5 Cron Job proc_open 和 ArgvInput 问题

Laravel 图像干预调整大小并放入存储

php - 哪个mysql函数等于php;密码哈希?

javascript - 仅当单击提交按钮时,如何让 Dropzone.js 上传文件?

php - 为什么 PHP 的 str_replace() 会导致编码问题?

php表单mysql错误到数据库

mysql - Laravel 迁移中的 Neo4j 和 Mysql