Make Controller Inside SubFolder in Laravel

In this article we will get to know how we can make a controller inside the subfolder in Laravel directly using the PHP artisan command, the need of doing this, sometimes we need our application in a more structured way.

Before moving forward let’s know what controller is and working principle of it.

What is Controller ?

Controllers are meant to group associated request handling logic within a single class. In your Laravel project, they are stored in the app/Http/Controllers‘ directory.

Get more information about the controller from this URL.

We will follow the below steps to create a controller inside a subfolder in Laravel

  • Install Laravel Application (ignore if already installed)
  • Write the code in command prompt.

Step-1: Download the Laravel Application

Open your command prompt under your htdocs and run the below command

composer create-project laravel/laravel laravel-vue-crud

Step-2: Open the command prompt.

Open the command prompt from the root directory of your project and enter the below command.

php artisan make:controller path/controller name

for example, I want to create a controller inside App/Http/Controllers/Student, then my command will be like below one

php artisan make:controller Student/StudentController

This command will create one controller file under App/Http/Controllers/Student named StudentController.php

I hope you enjoy the article, please rate me so that I can keep posting new technology stuff.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

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

Back to top button