crud<T extends Model> method
Implementation
void crud<T extends Model>({String prefix = "", required ModelCrudController<T> controller}) {
String getModelPath() {
final loweredHyphenate = T.toString().replaceAllMapped(RegExp(r'(?<=[a-z])(?=[A-Z])'), (match) => '-').toLowerCase();
return loweredHyphenate.endsWith("/") ? loweredHyphenate : "${loweredHyphenate}s";
}
if (!prefix.endsWith('/')) prefix = '$prefix/';
final path = getModelPath();
group(
prefix: "$prefix$path",
routes: () {
// index
get("/", controller.index);
// create
get("/create", controller.create);
// store
post("/create", controller.store);
// show
get("/{id:int}", controller.show);
// edit
get("/{id:int}/edit", controller.edit);
// update
patch("/{id:int}/edit", controller.update);
// destroy
delete("/{id:int}", controller.destroy);
},
);
}