Return back not working
Hello, I'm trying to return back(); but when it happens it only returns the data, not the view. Any ideas on how to fix it?
Here is my function:
public function store(Reply $reply)
{
return $reply->favorite();
return redirect()->back();
}
``
And here is the response:
{"user_id":476,"favorited_id":6,"favorited_type":"App\Reply","updated_at":"2019-03-28 07:49:50","created_at":"2019-03-28 07:49:50","id":2}
return $reply->favorite();
return redirect()->back(); // this is dead code
Second return will never be reached..because one line above you already have returned
https://www.php.net/manual/en/function.return.php
Solution is
$reply->favorite();
return redirect()->back();
@SERGIU17 - Yeah didn't see that I was returning the $reply->favorites();. Thank you @sergiu17!
Please or to participate in this conversation.