Skip to content

Controller

Class based controller

dox create:controller Blog
AppController controller = AppController()
Route.get('/ping', controller.ping);
class AppController {
    ping(DoxRequest req) {
        return 'pong';
    }
}

with static method

You can also use as static method in the controller.

Route.get('/ping', AppController.ping);
class AppController {
    static ping(DoxRequest req) {
        return 'pong';
    }
}

Function based controller

Route.get('/ping', listBlog);
listBlog(DoxRequest req) {
    return 'pong';
}

Resource controller

dox create:controller Blog -r
import 'package:dox_core/dox_core.dart';

class BlogController {
    /// GET /resource
    index(DoxRequest req) async {}

    /// GET /resource/create
    create(DoxRequest req) async {}

    /// POST /resource
    store(DoxRequest req) async {}

    /// GET /resource/{id}
    show(DoxRequest req, String id) async {}

    /// GET /resource/{id}/edit
    edit(DoxRequest req, String id) async {}

    /// PUT|PATCH /resource/{id}
    update(DoxRequest req, String id) async {}

    /// DELETE /resource/{id}
    destroy(DoxRequest req, String id) async {}
}