我让这个 API 控制器从 URL 接收数据并将其存储到数据库中,我想将其存储到本地存储中并将我重定向到另一个页面。在我的代码中,当我删除重定向部分时,数据已成功存储到本地存储和数据库中,但我需要这两个进程,存储到本地存储并将我重定向到另一个页面。
public function storePayment(Request $request)
{
$payment = new Payment();
$payment->user_id = $request->user_id;
$payment->save();
return "<script>
localStorage.setItem('user_id', JSON.stringify($user_id));
localStorage.setItem('request_id', {$payment->request_id});
localStorage.setItem('price', {$payment->price});
localStorage.setItem('user_phone', {$payment->user_phone});
window.location.href = 'https://my-app.com/app/payment';
</script>";
}