Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

400
Vistas
How to get variable from controller onto blade file? Laravel 8

I am trying to get the return ($orders_box) of a function in my controller into my blade file javascript so that I can display it on a table on my blade file.

Right now the blade code looks like this:

    function checkOrderId () {
        const orderID = document.getElementById('PolarisTextField2').value;
        const response = localStorage.getItem('orders_box');
        fetch('/checkBalanceRoute/' + orderID)
            .then(response => console.log(response))
    }

and the controller code looks like:

{
    public function checkBalance ($orderID){
        $shop = Auth::user();
        $req = $shop->api()->rest('GET', "/admin/api/2022-04/orders/$orderID.json");
        $orders = $req['body']['orders'];
        $orders_box = [];
        foreach ($orders as $order) {
            $data = array(
                'Order Id' => $order->id,
                'Total Price' => $order->total_price,
                'Name' => $order->billing_address->name,
            );

        array_push($orders_box, $data);
        }
    return response() ->json([
        'success' => true,
        'order_box' => $orders_box
    ], 200);

    }

Any thoughts?

I appreciate the help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of print_r($orders_box); use

return response()->json([
  'success'   => true,
  'order_box' => $order_box 
], 200);

This will return a response to your API.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda