Cuando al usuario le gusta una historia en la tarjeta, los usuarios la guardan con el botón "guardar". Hago esto como un savePost en mi archivo .js. Pero si el usuario no está registrado, estoy redirigiendo como "ubicación.reemplazar (APP_URL + "/login")".
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") } }) }
Su JS actual:
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") } }) }
Al final de su página de destino agregue:
@if(isset($_GET['showModal']) && $_GET['showModal'] == 1) <script type='text/javascript'> $(window).on('load', function() { $('#your modal id').modal('show'); }); </script> @endif
En tus rutas/web.php agrega esto:
Route::get('/', function () { if(Auth::guest()){ return view('target.page'); } else { return redirect('/somewhere'); } });