For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

Laravel Controller - Infovistar

Laravel Controller

In the MVC framework, the letter ‘C’ stands for Controller. It acts as directing traffic between Views and Models. Controllers are used to handle the request logic within a single class, and the controllers are defined in the app/http/Controllers directory.

Creating a Controller

Open the command prompt or terminal based on the operating system you are using and type the following command to create a controller using the Artisan CLI (Command Line Interface).

php artisan make:controller <controller-name>

Replace the <controller-name> with the name of your controller. The created controller can be called from app/routes/web.php by the following syntax.

Route::get('base URI','controller@method');

Step 1 − Execute the following command to create UserController.

php artisan make:controller UserController

Step 2 − After successful execution, you will receive the following output.

Laravel controller

Step 3 − You can see the created controller at app/Http/Controller/UserController.php with some basic coding already written for you and you can add your coding based on your need.

<?php

namespace App∖Http∖Controllers;

use Illuminate∖Http∖Request;

class UserController extends Controller
{
    //
}
-->