Actions

Introduction

An action is a method that you specify in a route that needs to be executed. The required Action must be specified in the route.

Examples

This method returns a Hello World string.

// app/Controllers/HomeController.php
namespace App\Controllers;

class HomeController{
    public function index(){
        return "Hello world";
    }
}

Specifying in routes

In this example, in the route we specify an index Action that will be called in the HomeController controller.

// routes/api.php
use Ghosty\Framework\Support\Facades\Route;

Route::get('/home')
    ->controller(\App\Controllers\HomeController::class)
    ->action('index');