Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
saving javascript variables from laravel blade.php to database

I am developing a product pricing calculator in laravel. Inside the <script> tag of blade.php i have some javascript variables like,

<script>
.........
front-end logics
.........
var country;
var product_type;
var product_link ;
var seller_shipping_fee;
var weight;
var dimensions;
........
........
</script>

I want to store those variables in the database. I have already created the table in database using laravel migration.

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePriceCalculatorResponsesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::connection('pgsql')->create('price_calculator__responses', function (Blueprint $table) {
            $table->increments('id');
            $table->string('country');
            $table->string('product_type');
            $table->string('product_link');
            $table->string('seller_shipping_fee');
            $table->string('weight');
            $table->string('dimension');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::connection('pgsql')->dropIfExists('price_calculator__responses');
    }
}

How do I save those Javascipt variables in the database?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

    <script>
    
      $(".save-data").click(function(event){
          event.preventDefault();
    
          let country = $("input[name=country]").val();
          let product_type = $("input[name=product_type]").val();
          let product_link = $("input[name=product_link]").val();
          let seller_shipping_fee = $("input[name=seller_shipping_fee]").val();
          ...............more variables..............
    
          $.ajax({
            url: "/ajax-request",
            type:"POST",
            data:{
              country:country,
              product_type:product_type,
              _token: _token,
................. more variables....................
            },
            success:function(response){
              console.log(response);
              if(response) {
                $('.success').text(response.success);
                $("#ajaxform")[0].reset();
              }
            },
            error: function(error) {
             console.log(error);
            }
           });
      });
    </script>

Something like that to put your on the right track, do not forget to have your input id match with yur variables if sending data is secure do not forget the token variale it is usually hidden input on symfony i dont know if it is the same case in Laravel. include ajax cdn too :)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda