How can get the data from the local storage every user's login in laravel 6?

Viewed 988

I want to condition the login redirection of user if the data of local storage is true or false,. example: if data is true,.. it will redirect it 1st page, else it will redirect it in 2nd page? Is their a laravel command or php command to get the values/data from local storage?

sorry for my english, i hope some one can help,. thanks

2 Answers

Laravel is build on PHP is server side language and there is no option to check the localstorage that is client side on server to load view. You will need to check the localstorage data in the view file and then redirect to the page as you need. Something like

<script>
   var user = localStorage.getItem('user');
   if(user){
      window.location.replace("http://stackoverflow.com/user_profile");
   } else {
      window.location.replace("http://stackoverflow.com/login");
   }
</script> 

Local storage is stored on the client side, so Laravel can't access it. You'll need to use JavaScript.

This is a similar question for an older version of Laravel, but it should help.

Related