-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal of compact syntax for Flight::route #579
Comments
Technically it seems like Flight::group, but it's for one controller |
I like where you're going with this. I'm not sure if an array is the best way to assign the methods, or if those methods should be automatically assumed.....or maybe both? If you assign them it will follow how you assign them, but if you don't it will assume a standard. And maybe you could override just one of the methods if you wanted? Just thinking out loud. |
If you only assign 3 methods with their respective controller methods, the rest could be assumed but only if those methods are defined in the controller |
So suppose I define to |
I think the use case is pretty good and the API is pretty easy to master. You have an api in Spanish, and you only need the GET / and the POST / mapped to listAll and handleSave Flight will see that there is no POST / definition to the store method, but since it is not defined it does not add it Using a resource controller would be as simple as Flight::route('/users', UserController::class); // UserController.php
class UserController {
function __construct(MyDependency $dep) {}
function index(): void {}
function show(string $id): void {}
function create(): void {}
function store(): void {}
function edit(string $id): void {}
function update(string $id): void {}
function delete(string $id): void {}
} |
I can get behind that. If you just define a controller then it will add those 7 routes by default. |
Here is another example of the requested behavior Flight::route('/posts', PostController::class); class PostController {
static function index(): void {}
static function show(string $id): void {}
} Flight will define the following routes: [
'GET /' => 'PostController::index',
'GET /@id' => 'PostController::show'
] |
Hi, Flight::resource('/posts', PostController::class); Like Laravel and CI4 does. ;) |
You may be late, but just in time 😊. Still haven’t made any formal decisions about what to call it. Resource definitely makes sense and is more explicit than just “knowing” that you could assign resources as another parameter. Still thinking about it 🤔 |
yeah, but what if you don't want to use the naming conventions for controller methods (index, store, etc...) the idea is customize names in route mapping |
Hi @fadrian06 , above you only show the case for traditional CRUD ( with all verbs), Not the solution for customization. For example, if you dont implement the edit or show CRUD, you can add a exception like Laravel or CI4 do. CI4 : routes->resource('photos', ['only' => ['index', 'update', 'delete']]);
// Or
$routes->resource('photos', ['except' => 'new, edit']); the customs routes should be created as normal. Nowadays for flexible router, if you are using a class (for controller) and PHP 8+, For simple projects or Web API, this lib does what is necessary, and above solution also would be enough for your case. ;) |
This is an alternative of Resource controllers, for people like me that name routes in spanish but controllers in english (for cohesion)
The text was updated successfully, but these errors were encountered: