Laravel | Controller Basics Last Updated : 30 Dec, 2019 Comments Improve Suggest changes Like Article Like Report Laravel is an MVC based PHP framework. In MVC architecture, 'C' stands for 'Controller'. A Controller is that which controls the behavior of a request. It handles the requests coming from the Routes. In Laravel, a controller is in the ‘app/Http/Controllers’ directory. All the controllers, that are to be created, should be in this directory. We can create a controller using ‘make:controller’ Artisan command. Syntax: php artisan make:controller UserController You can specify any name in place of ‘User’, but according to the naming convention of Laravel, you have to specify the word ‘Controller’ at the end for any name you specify. Example: Let's create a controller by running the following command: php artisan make:controller GfGController This will create a file in ‘app/Http/Controllers’ directory with the name ‘GfGController.php’. A controller class is also created in this file with the same name. Now that we have a controller created, lets define a public function with the name ‘index’ and specify our view file name (we will create it in the next step). php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class GfGController extends Controller { public function index() { return view('gfg'); } } Now we have to create and write the code for our view file that we specified in our ‘GfGController.php’. We will create a ‘gfg.blade.php’ file in ‘resources/views’ directory. html <!DOCTYPE html> <html> <head> <title>GfG</title> <style> h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3>A computer science portal for geeks</h3> </body> </html> Now the last thing to do is to write the route in the ‘web.php’ file in ‘routes’ directory. Route::get('gfg', 'GfGController@index'); Here, we have define the route ‘gfg’ in the first parameter (you can specify anything according to your need), and then the name of the controller we created in the previous step. Also, it important that at the end we specify the function name that we have defined in the controller class, separated by an ‘@’ symbol in between. Note: To get the output, we have to write ‘/gfg’ at the end of the URL. Output: Reference: https://laravel.com/docs/6.x/controllers Comment More infoAdvertise with us Next Article Laravel | Controller Basics aakashpawar1999 Follow Improve Article Tags : Technical Scripter Web Technologies PHP Laravel Similar Reads Laravel | Eloquent Model Basics Laravel is an MVC based PHP framework. In MVC architecture, âMâ stands for âModelâ. A Model is basically a way for querying data to and from the table in the database. Laravel provides a simple way to do that using Eloquent ORM (Object-Relational Mapping). Every table has a Model to interact with th 5 min read Laravel | View Basics Laravel is an MVC based PHP framework. In MVC architecture, V stands for View. The View is data that is going to be displayed to the user on their browser and the user can interact with it. It is simply an interface provided to the user for interaction. Laravel used a powerful templating engine call 8 min read AngularJS $controller Service AngularJS applications depend on a controller to control the flow of data through an AngularJS application. AngularJS architecture uses the MVC model i.e the Model View Controller. The model is responsible for maintaining the application data, the View for displaying data or some part of data to the 5 min read Laravel | Artisan Console Introduction Laravel has its own Command Line interface called Artisan. Its like a Linux command line but the commands are helpful for building a Laravel application. With this command-line tool, we can make models, controllers, and can do data migrations and many more. First, we will have to change the director 2 min read Laravel | Routing Basics Once you have installed Laravel and your basic Web App is up and running. Let's just look more deeply into the framework and see how we can work with routes. Routes: Routes are actually the web URLs that you can visit in your web application. For example /home, /profile, /dashboard etc are all diff 4 min read Laravel Features Laravel is an open-source web framework written in PHP that follows the modelâviewâcontroller (MVC) architectural pattern. It is intended for the development of web applications following the principles of modelâviewâcontroller (MVC) architecture. Laravel is free and open-source and released under t 2 min read AngularJS ng-controller Directive The ng-controller Directive in AngularJS is used to add a controller to the application. It can be used to add methods, functions, and variables that can be called on some event like click, etc to perform certain actions. Syntax: <element ng-controller="expression"> Contents... </element 2 min read Laravel | Migration Basics In Laravel, Migration provides a way for easily sharing the schema of the database. It also makes the modification of the schema much easier. It is like creating a schema once and then sharing it many times. It gets very useful when you have multiple tables and columns as it would reduce the work ov 4 min read AngularJS Controllers In this article, we will see the Controller in AngularJS along with knowing how Controller works, the concept of the Controller method & how the Controller can be implemented in an external. We will understand all these aspects with the help of their implementation & accordingly will its ill 3 min read Ember.js Controller actions Property Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. C 3 min read Like