{"id":22513,"date":"2021-07-19T13:39:53","date_gmt":"2021-07-19T13:39:53","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=22513"},"modified":"2022-04-13T15:56:34","modified_gmt":"2022-04-13T15:56:34","slug":"complete-guide-and-tutorials-for-routing-in-laravel","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/complete-guide-and-tutorials-for-routing-in-laravel\/","title":{"rendered":"Complete Guide and Tutorials for Routing in Laravel"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Routing<\/span><\/h2>\n\n\n\n<p>All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework.<br>The <strong>routes\/web.php<\/strong> file defines routes that are for your web interface.<br>For most applications, you will begin by defining routes in your <strong>routes\/web.php<\/strong> file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Syntax:-<\/strong><\/h4>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/28dd8dd4b3f082de476a1202bccc372c.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Route Returning String<\/span><\/h3>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/4c47e8a52bb23541b646ce23ab9d95b7.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Routes Parameter<\/span><\/h2>\n\n\n\n<p>Sometimes you will need to capture segments of the URI within your route. For example, you may need to capture a user&#8217;s ID from the URL.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/9f0ec33f5a541a16896c1f624832ab24.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Routes Multiple Parameter<\/span><\/h3>\n\n\n\n<p><strong>Note &#8211;<\/strong> Route parameters are always encased within {} braces and should consist of alphabetic characters, and may not contain a &#8211; character.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/37d77d7d6896db0868441568476dcd59.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Optional Routes Parameter<\/span><\/h3>\n\n\n\n<p>We can make optional parameter by placing a <strong>?<\/strong> Mark after the parameter name.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/03b01388b38d28484bb74c43f1516773.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Routes Parameter and Regular Expression<\/span><\/h3>\n\n\n\n<p>You may constrain the format of your route parameters using the where method on a route instance. The where method accepts the name of the parameter and a regular expression defining how the parameter should be constrained.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/5bf44d314997efed13428f3dae64f0af.js\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"text-decoration: underline;\">Routes Parameter with Regular Expression Helper Method<\/span><\/h3>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/fb1182ac69938f4a869b1710acb8b135.js\"><\/script>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Routing All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework.The routes\/web.php file defines routes that&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-22513","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/22513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=22513"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/22513\/revisions"}],"predecessor-version":[{"id":22544,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/22513\/revisions\/22544"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=22513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=22513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=22513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}