Controllers
Introduction
Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. Controllers can group related request handling logic into a single class. Controllers are stored in the application/Http/Controllers
directory.
Defining Controllers
Below is an example of a basic controller class. Note that the controller extends the base controller class included with Laravel. The base class provides a few convenience methods such as the middleware method, which may be used to attach middleware to controller actions:
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class ProfileController extends Controller
{
public function index() {
return view('profile/index');
}
}
You can define a route to this controller action like so:
$router->get('profile', 'ProfileController@index');