我有这样的功能:
protected function delete_failed_payment($token)
{
$invoice = Invoice::where("owner_id",Auth::user()->owner_id)
->where("token",$token)
->where("completed","0")
->first();
Invoice::destroy($invoice->id);
return redirect("/")->withErrors("Fail!");
}
调用此函数后,记录被成功删除,但我收到此错误响应:
UnexpectedValueException
Response内容必须是字符串或对象实现 __toString()," boolean"给出。
... / vendor / symfony / http-foundation / Response.php第407行
我希望它能将我重定向到" /"但即使记录被删除而且似乎没有问题,它也不会让我。
我也试过这个:
$invoice = Invoice::where("owner_id",Auth::user()->owner_id)
->where("token",$token)
->where("completed","0")
->delete();
与之前的结果相同。
任何帮助?
答案 0 :(得分:1)
尝试
protected function delete_failed_payment($token)
{
$invoice = Invoice::where("owner_id",Auth::user()->owner_id)
->where("token",$token)
->where("completed","0")
->first();
Invoice::destroy($invoice->id);
return redirect('/')
->withErrors(array('message' => 'Fail!'));
}
答案 1 :(得分:1)
试试这个。
protected function delete_failed_payment($token)
{
$invoice = Invoice::where("owner_id",Auth::user()->owner_id)
->where("token",$token)
->where("completed","0")
->first();
$invoice->delete();
return redirect->to("/")->withErrors("message" => "Fail!");
}