【问题标题】:Laravel Return value is expected to be 'illuminate\Http\Response', 'string' returnedLaravel 返回值应为 'illuminate\Http\Response',返回 'string'
【发布时间】:2018-08-02 09:32:47
【问题描述】:

你好有这个功能,它是返回文件的路径。

public function filecreate()
{
    $myHelper = new MyHelper();
    $path = $myHelper->create();

    return $path;
}

phpStorm 显示警告

返回值应为'illuminate\Http\Response',返回'string'

【问题讨论】:

  • 您的问题不在问题中包含的代码中。请检查堆栈跟踪以确定实际错误在哪里

标签: php laravel


【解决方案1】:

你必须使用 Response 对象作为回报,像这样的 helper:

return response(%path_to_view);

【讨论】:

  • 我不会返回查看
  • 请显示更多代码,以便我们将其放入上下文中
【解决方案2】:

response() 助手可用于生成其他类型的响应实例。 source

返回简单字符串使用:

return response($path)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 2013-05-28
    • 2021-11-25
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    相关资源
    最近更新 更多