Entonces, actualmente, tengo una página y necesito llamar a una ruta, y la respuesta JSON que devuelve, necesito almacenarla en una variable en mi página chat.blade.php. Intenté usar {{ruta}} como verá en el código, pero eso no me devolvería a mi chat.blade, a menos que agregara una redirección (), -> ruta () a /me, pero luego Me quedé atrapado en un bucle.
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 ---Ruta
Route::get('/me', [MeController::class, 'me'])->name('profiles-me')->middleware('auth:profile');