当我做console.log(结果)时,我想将这个结果保存为amount;我看到它知道我输入了什么数字,但是如何将它保存在Laravel函数中?
function makeOffer(nftid) {
swal({
title: "Do you want to make offer?",
text: "Enter amount",
input: 'text',
type: 'warning',
showCancelButton: true,
showConfirmButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
}).then((result) => {
if (result) {
axios.post("/myaccount/makeoffer/" + nftid).then(response => {
window.location.reload();
});
}
});
}
public function makeOffer($id, Request $request){
$nft=NFT::where('id','=',$id)->first();
if($nft->status=='pending') {
$nft_auction = new NftAuctions();
$nft_auction->nft_id = $nft->id;
$nft_auction->owner_id = $nft->user->id;
$nft_auction->buyer_id = Auth::id();
$nft_auction->amount = "there should be amount";
$nft_auction->status = 'pending';
$nft_auction->save();
return back();
}
else{
abort(404);
}
}发布于 2022-07-13 14:11:59
Axios的.post()方法采用两个参数;URL和要发送到后端的数据,因此将其调整为:
axios.post("/myaccount/makeoffer/" + nftid, {'amount': result})
.then(response => {
window.location.reload();
});然后,在后端,您可以以$request->input('amount')的形式访问它。
public function makeOffer($id, Request $request){
$nft = NFT::find($id);
if($nft->status == 'pending') {
$nftAuction = new NftAuctions();
// ...
$nftAuction->amount = $request->input('amount');
// ...
$nftAuction->save();
return back();
}
}一些注意事项:
Model::where('id', '=', $id)->first()可缩短为Model::find($id)。PascalCase和单数:NFT应该是Nft,NftAuctions应该是NftAuction文档:
https://stackoverflow.com/questions/72967605
复制相似问题