Controllers
Creating
To quickly generate a new controller, you may run the make:controller Nailer command. By default, all of the controllers for your application are stored in the app/controllers directory.
php nailer make:controller UserController
Here is a basic controller example. In this example we get a list of all records from the Users table.
namespace App\Controllers;
use App\Models\User;
class UserController extends Controller
{
public function Index()
{
$User = new User;
$Users = $User->all();
return response($Users);
}
}
The controller usage is identical to that specified when registering the route.
use App\Controllers\UserController;
$Route->Add()
->get('/users')
->controller(UserController::class)
->action('Index');