Skip to content
On this page

Controllers

Controllers are responsible for receiving the request and displaying the result of the operation. A controller determines what response to send back to a user when a user makes a browser request.

It uses inheritance property of OOP programming approach and uses base controller. The cms use ResourceController as a base controller.

How to use controller

Below is the basic example that shows how controllers are used:

use App\Http\Controllers\System\ResourceController;

class UserController extends ResourceController
{
    public function __construct(UserService $userService)
    {
        parent::__construct($userService);
    }

    public function storeValidationRequest()
    {
        return 'App\Http\Requests\system\userRequest';
    }

    public function moduleName()
    {
        return 'users';
    }

    public function viewFolder()
    {
        return 'system.user';
    }
}

Instead of using static value everytime, we generally specify essential property needed for the controller in our controllers function like the page title, view file location, url and the module with the this keyword inside the constructor which makes it easier to access them. The base constructor can be overridden if we want to modify the functions of the base controller.