What is a Laravel Controller

Posted on by

What is a Laravel Controller

The controller works as an intermediate layer between Views and Models. In this short article, I will tell about detailed information regarding controllers in Laravel.

Creating a Controller

We just have to follow some simple steps to create a controller in laravel. First, you need to open your command prompt by searching cmd in your system and type the command to create a controller using the Artisan Command Line Interface.

Step 1 − 

In the First Step copy and paste the following command to create UserController.

(php artisan make:controller UserController –plain)

Note: Here (UserController) is the name of the controller you want to create change it accordingly.

Step 2 −

After some time you will receive (controller created successfully) message in the console.

Step 3 −

Now you can view the recently created controller just navigate to app/Http/Controller/MyController.php with some piece of code and you can add your coding based on your requirements.

Step 4 − 

Now you can launch the application on the internal web server by executing the following command

(php artisan serve)

Step 5− 

The final step is to just visit the following URL:- 

(http://localhost:8000/usercontroller/path)

Note:  Here localhost is the server base URL it may be different as per you domain or server.

Conclusion

PHP is a powerful language. Laravel is a famous and robust PHP framework. It provides an efficient way of tracking SQL queries.  You can easily find all your models in the main app directory in the root of the project.

Final Words

I hope this article helps you know better about Laravel Controller. If it is useful for you in any manner, then do share it on social media, stay connected with me for the new update & contact me for any inquiry. 

Comments

Leave a comment

Your email address will not be published.
Required fields are marked *