Controllers
Controllers
Akash Pundir
Assistant Professor
System Programming -I
• In Laravel, a controller is a crucial
component used to handle HTTP
requests and define the application's
response logic. Controllers serve as
an intermediary between routes and
the actual business logic of your
application.
Controllers
• Instead of defining all of your request handling logic as
closures in your route files, you may wish to organize this
behavior using "controller" classes.
use App\Http\Controllers\UserController;
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Controllers\ProvisionServer;
Route::post('/server', ProvisionServer::class);
Writing Controllers(contd.)
• You may generate an invokable controller by using
the --invokable option of the make:controller Artisan
command:
use App\Http\Controllers\UserController;