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

308
Visualizações
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 à 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