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

164
Vistas
Javascript Redirect Modal in Laravel

When the user likes a story on the card, users saves it with the "save" button. I do this as a savePost in my .js file. But if the user is not registered I am redirecting as "location.replace(APP_URL + "/login")".

I want to redirect to a modal on the homepage instead of /login. Is it possible for me to do this as a session or something?

function savePost(t) {
    $.ajaxSetup({
        headers: {
            "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
        }
    });
    $(this);
    $.ajax({
        url: APP_URL + "/save_favorite",
        type: "POST",
        dataType: "json",
        data: {
            item: t,
            _token: $('meta[name="csrf-token"]').attr("content")
        },
        success: function(e) {
            1 == e.bool ? $("#save-icon-" + t).removeClass("text-muted").addClass("icon-filled") : 0 == e.bool && $("#save-icon-" + t).removeClass("icon-filled").addClass("text-muted")
        },
        error: function(e) {
            location.replace(APP_URL + "/login")
        }
    })
}
about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Your current JS:

 function savePost(t) {
        $.ajaxSetup({
            headers: {
                "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")
            }
        });
        $(this);
        $.ajax({
            url: APP_URL + "/save_favorite",
            type: "POST",
            dataType: "json",
            data: {
                item: t,
                _token: $('meta[name="csrf-token"]').attr("content")
            },
            success: function(e) {
                1 == e.bool ? $("#save-icon-" + t).removeClass("text-muted").addClass("icon-filled") : 0 == e.bool && $("#save-icon-" + t).removeClass("icon-filled").addClass("text-muted")
            },
            error: function(e) {
                location.replace(APP_URL + "/targetPage?showModal=1")
            }
        })
    }

At the end of your target page add:

@if(isset($_GET['showModal'])  && $_GET['showModal'] == 1) 
<script type='text/javascript'>
    $(window).on('load', function() {
        $('#your modal id').modal('show');
    });
</script>
@endif

In your routes/web.php add this:

Route::get('/', function () {
    if(Auth::guest()){
        return view('target.page');
    } else {
        return redirect('/somewhere');
    }
});
about 4 years ago · Santiago Gelvez 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