Problems with laravel using blade

My script from the view blade is executing first than my scripts in the layout view

Hi everyone i’m learning to use Laravel and actually i want to use some code javascript in it, i’m using a layout i show you in the next code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>@yield('title')</title>
@vite('resources/css/app.css')
</head>
<body class="bg-slate-900 text-white overflow-hidden">
<header class="flex flex-row p-8 bg-slate-950">
<div>
<h3 class="font-bold text-2xl">@yield('nav-title')</h3>
</div>
<nav class="w-full flex flex-row-reverse ">
@yield('nav-options')
</nav>
</header>
<div class="flex flex-row">
<aside class=" bg-slate-950 h-dvh">
<nav class=" flex flex-col w-40">
<a href="{{ route('productos.inicio') }}" class=" text-center flex flex-col hover:bg-green-500 p-4 transition-colors"> <i class="fa-solid fa-bag-shopping text-zinc-50"></i> Productos</a>
<a href="" class=" text-center flex flex-col hover:bg-blue-500 p-4 transition-colors"> <i class="fa-solid fa-book-open"></i>Categorias</a>
<a href="" class=" text-center flex flex-col hover:bg-yellow-500 p-4 transition-colors"> <i class="fa-solid fa-wallet"></i>Ventas</a>
<a href=""></a>
</nav>
</aside>
<main class=" m-8 w-full max-h-full overflow-auto">
@yield('content')
</main>
</div>
<footer>
@yield('footer-content')
</footer>
@vite('resources/js/app.js')
<script>
let token;
//Obtener token para realizar las solicitudes post
fetch('one_fetch_petition')
.then(response => {
if (!response.ok) {
throw new Error('Error en la solicitud: ' + response.status);
}
return response.json();
})
.then(data => {
// Éxito, manejar la respuesta JSON
token = data.token;
})
.catch(error => {
// Si no se obtuvo resultado el token será 0
token = 0;
console.log("Error al hacer la petición del token: " + error);
});
</script>
@stack('scripts')
</body>
</html>
</code>
<code><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>@yield('title')</title> @vite('resources/css/app.css') </head> <body class="bg-slate-900 text-white overflow-hidden"> <header class="flex flex-row p-8 bg-slate-950"> <div> <h3 class="font-bold text-2xl">@yield('nav-title')</h3> </div> <nav class="w-full flex flex-row-reverse "> @yield('nav-options') </nav> </header> <div class="flex flex-row"> <aside class=" bg-slate-950 h-dvh"> <nav class=" flex flex-col w-40"> <a href="{{ route('productos.inicio') }}" class=" text-center flex flex-col hover:bg-green-500 p-4 transition-colors"> <i class="fa-solid fa-bag-shopping text-zinc-50"></i> Productos</a> <a href="" class=" text-center flex flex-col hover:bg-blue-500 p-4 transition-colors"> <i class="fa-solid fa-book-open"></i>Categorias</a> <a href="" class=" text-center flex flex-col hover:bg-yellow-500 p-4 transition-colors"> <i class="fa-solid fa-wallet"></i>Ventas</a> <a href=""></a> </nav> </aside> <main class=" m-8 w-full max-h-full overflow-auto"> @yield('content') </main> </div> <footer> @yield('footer-content') </footer> @vite('resources/js/app.js') <script> let token; //Obtener token para realizar las solicitudes post fetch('one_fetch_petition') .then(response => { if (!response.ok) { throw new Error('Error en la solicitud: ' + response.status); } return response.json(); }) .then(data => { // Éxito, manejar la respuesta JSON token = data.token; }) .catch(error => { // Si no se obtuvo resultado el token será 0 token = 0; console.log("Error al hacer la petición del token: " + error); }); </script> @stack('scripts') </body> </html> </code>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>@yield('title')</title>
    @vite('resources/css/app.css')
</head>

<body class="bg-slate-900 text-white overflow-hidden">
    <header class="flex flex-row p-8 bg-slate-950">
        <div>
            <h3 class="font-bold text-2xl">@yield('nav-title')</h3>
        </div>

        <nav class="w-full flex flex-row-reverse ">
            @yield('nav-options')
        </nav>
    </header>

    <div class="flex flex-row">
        <aside class=" bg-slate-950 h-dvh">
            <nav class=" flex flex-col w-40">
                <a href="{{ route('productos.inicio') }}" class=" text-center flex flex-col hover:bg-green-500 p-4 transition-colors"> <i class="fa-solid fa-bag-shopping text-zinc-50"></i> Productos</a>

                <a href="" class=" text-center flex flex-col hover:bg-blue-500 p-4 transition-colors"> <i class="fa-solid fa-book-open"></i>Categorias</a>

                <a href="" class=" text-center flex flex-col hover:bg-yellow-500 p-4 transition-colors"> <i class="fa-solid fa-wallet"></i>Ventas</a>
                <a href=""></a>
            </nav>
        </aside>
        <main class=" m-8 w-full max-h-full overflow-auto">
            @yield('content')
        </main>
    </div>

    <footer>
        @yield('footer-content')
    </footer>

    @vite('resources/js/app.js')
    <script>
        let token;
        //Obtener token para realizar las solicitudes post
        fetch('one_fetch_petition')
            .then(response => {
                if (!response.ok) {
                    throw new Error('Error en la solicitud: ' + response.status);
                }
                return response.json();
            })
            .then(data => {
                // Éxito, manejar la respuesta JSON
                token = data.token;
            })
            .catch(error => {
                // Si no se obtuvo resultado el token será 0
                token = 0;
                console.log("Error al hacer la petición del token: " + error);
            });
    </script>
    @stack('scripts')
</body>

</html>

The problem is, when i use it another view using this layout it chargues first the script in that view when i think it should be reverse i mean, the first script charged should be from the layout and i can’t use code from app.js for that problem 🙁
I’ll adjunt a picture showing that i want to express

enter image description here

New contributor

Jonathan JV is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật