Laravel Flexible Routing with Auto-Redirects: Versioning Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys today I will show you one interesting concept of routing based on Native php.com website code which is open source on GitHub and side note I know it's Lille 11 already out and some of you may expect the video but I'm still working on that I'm trying to be not the first to talk about new versions but spend a bit more time on a better video so that's coming in a few days but for now we're looking at Native php.com webbsite which I cloned locally and it looks like this documentation website I mean the homepage looks like this and if you click get started interesting things happen so the URL is SL do SL1 and then the actual URL you land on is this so how does that magic happens and this is the routes with page here and page here and controller here and some redirects and interesting logic so I thought to Showcase you this code it would be useful for any of you who would build especially the documentation page like this one or any website that require versioning with information first credit to the authors of native PHP website and Native PHP in general but in this case we're talking about not the tool but the website of that so Simon Hamp and Marcel poot are the top contributors along with a few others now let's dive into the code and see the logic first what happens if I go to/ docs SL1 it is covered by this route get so docs one that page with question mark is optional and there are also a few checks that page can be anything a string but version needs to be a number so I cannot go to Doc SL ABC that would be considered a page and then I land on a controller which is a single action controller invocable controller with invoke method with a bit more logic about routing now the docs themselves are not in the database as you can see resource path views docks and then version and the docks are here on the left sidebar for example if we go to getting started an open installation for example it's a markdown file which is then pared by markdown tools but basically if you don't have that file in the resources views then Lille shows 404 not found page and then if the page is null which is null in our case there's a separate method called redirect to First navigation page so if we navigate to that it's quite a big method with collection filtering looking for key and getting the first page that fits I will not explain it in detail in this video I will link the source code in the description below what you need to understand though is the logic that route points to the controller and then controller builds the URL if it's not present and then redirects to the appropriate page and then also in the routes you see/ do/ page which is without version so for example even if I go just to slash docs where it would redirect to the same page so it would automatically get the version to version one then redirect to docs one and then I would land here and I would be redirected again to version one getting started page also they're playing with refer I guess that's for the the future when they have version two or three for now latest version is still one so some string operations with getting the version correctly so yeah what do you think about this example of routing flexible routing with redirects to the correct version and correct default page would you have done something differently let's discuss in the comments below and also on this channel I will shoot a few more videos about that native PHP website because I see interesting Solutions like spyy laral menu package to build this menu on the left like caching solution and a few more so subscribe to the channel to not miss those videos along with the ones about laral 11 I'm planning to shoot quite a few about new functions and changes so again subscribe and see you guys in other videos
Info
Channel: Laravel Daily
Views: 5,919
Rating: undefined out of 5
Keywords:
Id: 50LaEB4CgRc
Channel Id: undefined
Length: 4min 19sec (259 seconds)
Published: Wed Mar 13 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.