Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
¿Cómo puedo pasar el RESULTADO de javascript a la función laravel como cantidad?

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); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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:

  1. Model::where('id', '=', $id)->first() se puede acortar a Model::find($id) .
  2. Los nombres de los modelos son PascalCase y singular: NFT debe ser Nft y NftAuctions debe ser NftAuction

Documentación:

Método Axios .post()

Laravel: Recuperando Entrada

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!