2017-10-24 1 views
0

を削除した後、私はこのような機能を持っているエラーを返します。この関数を呼び出した後Laravelがレコード

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

応答コンテンツは、 __toString()を実装する文字列またはオブジェクトである必要があります。

... /ベンダー/ symfonyの/ HTTP-基礎/ Response.php線407

私はそれを「/」に私をリダイレクトするように期待していますが、レコードが削除されるにもかかわらず、とは問題なさそうですそれは私に許されません。

また、私は、この試みている:前と同じ結果で

$invoice = Invoice::where("owner_id",Auth::user()->owner_id) 
     ->where("token",$token) 
     ->where("completed","0") 
     ->delete(); 

を。

助けが必要ですか?

答えて

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!')); 
} 
+0

いいえ、これは確かに戻り値ではなく、クエリを破棄することです。 – prgrm

+0

これを '/ {dd($ errors)}}'ビューに追加すると返されるものは? – kerrin

+0

リダイレクトの 'withErrors'部分をテストとして削除してください。問題はリダイレクトに付随する応答だと思います。削除はそのサウンドによって正常に機能しています。 – kerrin

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!"); 
} 
関連する問題