how to create middleware in laravel - laravel

I have created the project which has login page login.blade.php which has only Regno to login-in.
once it login is the success it will redirect to home.blade.php and it followed by 4 more pages when clicking of next button in each page
page2.blade.php,page3.blade.php,page4.blade.php,page5.blade.php and finally, it should redirect to login page itself. The problem is the browser back button should not allow it to go back to the previous page.
can anyone suggest me how to create middleware for this?
thank you.

The browser's back button is not controlled by the server, where Laravel runs. There is no way for you to block it or interact with it in any way inside your PHP code.
What you can do is send XMLHHTTPRequest (XHR) with JavaScript. They ensure that on a button click you will stay on the same page in the browser and then your JS-code can read the server response (your rendered page templates) and replace the current content with the one from that response. You can read more on this when you google for AJAX, e.g. this article: https://www.sitepoint.com/use-jquerys-ajax-function/

Read this thing. I once implemented in the same way. By setting cache control in response header.
https://stackoverflow.com/a/51821808/10239067

Related

Issue with laravel route with Ajax

I have my main container (app.blade.php) and inside it I have my home.blade, inside there is a container that refreshes with ajax after clicking an item in the sidenav menu. If you click one of those items when the session has expired, a middleware redirects you to the login (or at least it’s meant to). This should happen
God login
The issue is that, when that event happens, it renders the login inside of the container refreshed with ajax, like in the picture below. Any idea of how to solve this?
Bad login
(Sorry if i have issues in my writing, i am still learning english and in stackoverflow in spanish nobody helps :/)
Your "middleware" is working OK, it is doing what is meant to do: Any petition to the server is transformed in a redirection to your login page. However, you are making an async call. I guess you are rendering whatever the result is in a container, resulting in your "bad login".
A possible solution is to add some parameter to your ajax requests in order to catch it on the server side and send you an error status instead of a redirection, then in your page handle that error as a browser redirection to your login.

How to do ajax loading with URL change but not page redirection?

If you carefully notice facebook, you will understand that the when you visit one page to another then the whole page is not refreshed or redirected but the URL changes when navigating to new page. It is more clear when chat windows are open, they remains static during page loading. As other website does this by using the # but facebook does not.
There is another example came to me: http://www.davidwalsh.name/. Visit the site and open other pages within their site and you will understand what I mean. Don't forget to notice the URL change.
How they do this?
Added More: I want a way that the page content will be loaded with ajax, change the URL for bookmark feature but when changing URL it should not reload / refresh the page by not using # (hash).
You have two questions:
For the URL change you can put the path instead of the # in the href property of the anchor (e.g /otherlink).
For opening the chat or opening some div does not require to send it in the url, its the onclick event on the div and its expands. Also the chat remains open may be thay set cookie or flag when the chat is first time opened and checking and changing the chat with flag they are setting.
As suggested by #andytuba
For Facebook, Google "hash navigation ajax".
For DavidWalsh, google "history API".

How does Facebook handle requests between Home page and Profile page

I am just wondering how facebook manage requests to "my profile page" and "home page" and some other pages that seem to reload just some content.
For example when I am on "my profile page" on facebook, i Hit the home button and the top bar button and chat panel on right side remain intact (they are not reloaded). I have monitored XMLHTTPRequest in webkit console and no ajax is generated, so its not Ajax (i think). Otherwise, if FULL http requests are generated when clicking those links, I thought the full page must be reloaded, I am right? So I have no clue how is this handled. Can you give me a hand please?
Thanks :)
It's a type of performance optimization called "quickling", they also use a "pagecache" strategy to reduce the data from server. In the lower level, it depends on javascript perform as a LinkController, which delegate a hyper-link click event and then send an ajax (or use iframe) to request the pagelet data from server, the response will be a json-formed data structure, then javascript will insert the content of current page. Uri in your address bar can be dealled with the hash change event in old browsers and H5's History API (pushState) to manage the history record of browser.

JSF and browser back

I have a very strict requirement to use POST to pass in request parameters to my application upon entry. Once entering the application (page1), entering form information and continuing to the next page (page2) via a commandButton, the expectation is that the data will be posted and later read from a session scoped manage bean. All works well except when using browser back on page2 to navigate back to page1.
I have tried adding a redirect tag on the navigation rule that navigates from page1 to page2 to no avail. I have also tried this implementation of the Post-Get-Redirect pattern (http://balusc.blogspot.com/2007/03/post-redirect-get-pattern.html). Am I missing something obvious here?
Abel, the scope of page1 is request.
The solution we came up with which is no means ideal is to disable browser caching on the previous page. What this means is that whenever you refresh the page using the browser refresh button or click the browser back button, the browser will indicate that the page is expired and prompt a warning asking whether you want to re-submit the request.
We do have a work around which is to provide navigation buttons within the webpage but the idea was to support browser back. This would be easy using GET parameters, but POST provides additional complexity which we have decided to mitigate by by providing our in-house navigation buttons.

Browser Back Button Handling in Ajax Based Application

Similar questions have been asked on SO, but I am still looking for a solution and not a workaround.
I am working on an Ajax based application and when the user clicks on the Browser Back Button it takes the user to the login page(every page after the login page is ajax loaded). Apparently, this is not what the user expected.
We recommended using Bread Crumbs to the client
*Page One >> Page Two >> Page Three*
but the client insists that they prefer to use the Browser Back Button. Is there a way where it is possible to somehow embed the Bread Crumb links to the Browser Cache...in other words, clicking the back button invokes the same actions which clicking the Bread Crumb links would?
Regards,
SB
You could use the RSH (reallysimplehistory) javascript library: http://code.google.com/p/reallysimplehistory/

Resources