{"id":8091,"date":"2021-08-25T06:51:57","date_gmt":"2021-08-25T06:51:57","guid":{"rendered":"https:\/\/www.scmgalaxy.com\/tutorials\/?p=8091"},"modified":"2021-08-25T06:51:58","modified_gmt":"2021-08-25T06:51:58","slug":"complete-referance-of-controller-in-laravel","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/","title":{"rendered":"Complete Referance of Controller in Laravel"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Controllers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Controllers can group related request handling logic into a single class. Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Controllers are stored in the <strong>app\/Http\/Controllers<\/strong> directory.<br>Controller extends the base Controller class included with Laravel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Defining Controller Class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Run Command:-<\/strong> php artisan make:controller<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example:-<\/strong> php artisan make:controller AboutController<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Path:-<\/strong> app\/Http\/Controllers\/AboutController.php<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/15a376629c13f858bd8359c5c9e94b39.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Route for Controller Class<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Path of Controller :-<\/strong> app\/Http\/Controllers\/AboutController.php<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/44d632b3d371e70440f35f40f6ac314e.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Path of Route:-<\/strong> routes\/web.php<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/0d3d8c15331db796bb1730cbc0d158c6.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Syntax:-<\/strong> Route::get(\u2018uri\u2019, [ControllerName::class, \u2018method_name&#8217;]);<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Passing Data from Controller to View<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"> <strong>Path of Controller :-<\/strong> app\/Http\/Controllers\/AboutController.php <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/3d0f03f1327d24ebb078cb919b51f10e.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"> <strong>Path of Route:-<\/strong> routes\/web.php <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/0d3d8c15331db796bb1730cbc0d158c6.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Path of View:-<\/strong> resources\/views\/aboutme.blade.php<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/f38fee746c7b3c235802d8956ea1f404.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Multiple Methods inside Controller<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">  <strong>Path of Controller :-<\/strong> app\/Http\/ControllersAboutController.php  <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/f98e57f25844f4bcf42b5a85ec1b3493.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">  <strong>Path of Route:-<\/strong> routes\/web.php  <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/8045c52d46df0bd8a058fffde23e9462.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"> <strong>Path of aboutme blade file:-<\/strong> resources\/views\/aboutme.blade.php <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/775978b9200e5f83ed8bbd8ac0e2043d.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">  <strong>Path of aboutyou blade file:-<\/strong> resources\/views\/aboutyou.blade.php  <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/5a16ef08d76f565583a296418274cca5.js\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Single Action Controller<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you would like to define a controller that only handles a single action, you may place a single __invoke method on the controller.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> <strong>Run Command:-<\/strong> php artisan make:controller ShowAbout &#8211;invokable<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">   <strong>Path of Controller :-<\/strong> app\/Http\/Controllers\/ShowAboutController.php   <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/674ebf9cd36c07883fcf6b0790667f56.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">   <strong>Path of Route:-<\/strong> routes\/web.php   <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/bcd8b912c4906124db62ee07907b3281.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\">  <strong>Path of aboutme blade file:-<\/strong> resources\/views\/aboutme.blade.php  <\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/amardeep-devopsschool\/775978b9200e5f83ed8bbd8ac0e2043d.js\"><\/script>\n","protected":false},"excerpt":{"rendered":"<p>Controllers Controllers can group related request handling logic into a single class. Instead of defining all of your request handling [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5049],"tags":[5052,177],"class_list":["post-8091","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Complete Referance of Controller in Laravel - scmGalaxy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Complete Referance of Controller in Laravel - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"Controllers Controllers can group related request handling logic into a single class. Instead of defining all of your request handling [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-25T06:51:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T06:51:58+00:00\" \/>\n<meta name=\"author\" content=\"Amardeep Dubey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amardeep Dubey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/\"},\"author\":{\"name\":\"Amardeep Dubey\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/097cf9059af187b39521d8641650ddda\"},\"headline\":\"Complete Referance of Controller in Laravel\",\"datePublished\":\"2021-08-25T06:51:57+00:00\",\"dateModified\":\"2021-08-25T06:51:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/\"},\"wordCount\":249,\"commentCount\":0,\"keywords\":[\"laravel\",\"Php\"],\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/\",\"name\":\"Complete Referance of Controller in Laravel - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-08-25T06:51:57+00:00\",\"dateModified\":\"2021-08-25T06:51:58+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/097cf9059af187b39521d8641650ddda\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/complete-referance-of-controller-in-laravel\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Complete Referance of Controller in Laravel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/097cf9059af187b39521d8641650ddda\",\"name\":\"Amardeep Dubey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79b318f73f1ee84d7678ea32f5af8984012529c7a67c2deb7e3030dc8c6114ba?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79b318f73f1ee84d7678ea32f5af8984012529c7a67c2deb7e3030dc8c6114ba?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/79b318f73f1ee84d7678ea32f5af8984012529c7a67c2deb7e3030dc8c6114ba?s=96&d=mm&r=g\",\"caption\":\"Amardeep Dubey\"},\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/amardeep\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Complete Referance of Controller in Laravel - scmGalaxy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/","og_locale":"en_US","og_type":"article","og_title":"Complete Referance of Controller in Laravel - scmGalaxy","og_description":"Controllers Controllers can group related request handling logic into a single class. Instead of defining all of your request handling [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/","og_site_name":"scmGalaxy","article_published_time":"2021-08-25T06:51:57+00:00","article_modified_time":"2021-08-25T06:51:58+00:00","author":"Amardeep Dubey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Amardeep Dubey","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/"},"author":{"name":"Amardeep Dubey","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/097cf9059af187b39521d8641650ddda"},"headline":"Complete Referance of Controller in Laravel","datePublished":"2021-08-25T06:51:57+00:00","dateModified":"2021-08-25T06:51:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/"},"wordCount":249,"commentCount":0,"keywords":["laravel","Php"],"articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/","name":"Complete Referance of Controller in Laravel - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-08-25T06:51:57+00:00","dateModified":"2021-08-25T06:51:58+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/097cf9059af187b39521d8641650ddda"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/complete-referance-of-controller-in-laravel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Complete Referance of Controller in Laravel"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/097cf9059af187b39521d8641650ddda","name":"Amardeep Dubey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/79b318f73f1ee84d7678ea32f5af8984012529c7a67c2deb7e3030dc8c6114ba?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/79b318f73f1ee84d7678ea32f5af8984012529c7a67c2deb7e3030dc8c6114ba?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/79b318f73f1ee84d7678ea32f5af8984012529c7a67c2deb7e3030dc8c6114ba?s=96&d=mm&r=g","caption":"Amardeep Dubey"},"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/amardeep\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=8091"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8091\/revisions"}],"predecessor-version":[{"id":8279,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/8091\/revisions\/8279"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=8091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=8091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=8091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}