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

304
Vistas
Call a route and store the payload in a variable in laravel

So currently, I have a page, and I need to call a route, and the JSON response it returns, I need to store it in a variable on my chat.blade.php page. I tried using {{route}} as you'll see in the code, but that wouldn't get me back to my chat.blade, unless I added a redirect(), ->route() to /me, but then I got stuck in a loop.

chat.blade.php

<div class="content">
<head>
    <script>
        // quick javascript to act as a client to our web socket server
        // to state the obvious, this has nothing to do with PHP; this is javascript
        var conn = new WebSocket('ws://localhost:9000');
        var meObj = {};
        // some basic call back functions when 
        // certain events happen on the web socket server

        // when we successfully connect, log a simple message
        conn.onopen = function (e) {
            meObj = {{ route('profiles-me') }};

            console.log("Connected!");
        };
 
--- redacted to keep it short ---

MeController.php

--- Redacted to keep it short ---
public function me()
    {
        /** @var User $user */
        $user = Auth::user();

        // Lets extract the APP_KEY string to decode it.
        $appKeyString = explode(':', env('APP_KEY'));
        
        $secret = base64_decode($appKeyString[1]);

        $signature = hash('sha256', $user->name . $secret);

        return response()->json([
            'me' => [
                'id'         => $user->id,
                'name'       => $user->name,
                'picture'    => $user->picture,
                'csrf_token' => csrf_token(),
                'sig'        => $signature,
            ]
        ]);
    }
--- Redacted to keep it short ---

Route

Route::get('/me', [MeController::class, 'me'])->name('profiles-me')->middleware('auth:profile');
about 4 years ago · Santiago Trujillo
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