Controller In Laravel

Posted by

Controllers can group related request handling logic into a single class, Instead of defining all of your request handling logic as closure in route files ,you may wish to organize this behavior using controller classes.

Controllers are stored in the app\Http\controllers directory

controller extends the base controller class include with Laravel

Defining Controller Class

We can define the controller class through running this command

— php artisan make: controller controller_NAME

Example :-

— php artisan make: controller About

Creating Route For Controller Class

we have to add the path in route to use this controller class through USE keyword

Example :- use\App\Http\controllers\About

Syntax

Route::get(‘url’,[controller_name::class,’method_name’];

Example

Route::get(‘About’,[about::class,’show’];

THANKU