Quiero guardar este resultado como cantidad, cuando hago console.log(result); Veo que sé qué número puse en la entrada, pero ¿cómo guardarlo en la función 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); } }El método .post() de Axios toma 2 argumentos; la URL y los datos que desea enviar al backend, así que ajústelos a:
axios.post("/myaccount/makeoffer/" + nftid, {'amount': result}) .then(response => { window.location.reload(); }); Luego, en su backend, puede acceder a esto como $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(); } }Algunas notas:
Model::where('id', '=', $id)->first() se puede acortar a Model::find($id) .PascalCase y singular: NFT debe ser Nft y NftAuctions debe ser NftAuctionDocumentación: