Closed soheilkhaledabdi closed 3 months ago
Abso-freakin-lutely! https://docs.flightphp.com/examples
I looked through your code and it is done very nicely! You've separated out your code very well and structured the design of it very very well! If you don't mind I have a couple suggestions maybe could help simplify it even further.
runway
you can add the flightphp/active-record plugin and you could create your models with php runway make:record users
. And it also has all the juicy bits to do some of what I saw.flight\Database\PdoWrapper
to simplify some of your database calls you made.Overall, solid project! Thanks so much for contributing that! Now go write an article on it on dev.to or something :laughing:
Hi, Thank you so much for your kind words and positive feedback about my project. I'm glad to hear you liked it, and I hope it can help new users get started with the Flight framework more easily.
I actually wrote an article about this project on dev.to! You can check it out here: https://dev.to/soheilkhaledabadi/build-a-simple-crud-api-in-php-with-the-flight-framework-5fnk. I hope it can provide even more insights into how to use Flight for building a CRUD API.
I also really appreciate your suggestions! I'll definitely look into how I can use runway
and the available plugins to simplify and optimize the code further. Using flightphp/active-record
and flight\Database\PdoWrapper
are great ideas, and I’ll work on incorporating them into the project.
Once again, thank you and the entire Flight team for all the support and the amazing work you do.❤️🙏
Awesome job all the way around! Hop in the chat room if you ever want to say hi! Thanks for your contributions!
Hello All,
Thanks a lot for your good example. I have a quick suggestion, to use Flight::json()
instead of echo json_encode()
. Besides this point, nice work!
https://github.com/soheilkhaledabdi/php-crud-api-flight/blob/main/app/Traits/ApiResponse.php
Thank you for the great suggestion. It has been implemented. Below is the link to the commit that was made
If you want to go further, you still could add return types to classes' methods. It improves type safety (fewer potential bugs) and helps with readability and maintainability. And even better, you can consider adding PHPStan for more quality checks :)
Good catch @pierresh There's also the Flight::jsonHalt() method if you need to serve json but immediately halt things afterwards. Not sure if you need it for your use case.
Thank you, everyone, for all your guidance. I’m using all your advice, and I’d be happy if you could message me on Telegram if there’s an issue or if you have more guidance for me.
My Telegram ID is: @soheilkhaledabadi.
Another point, it is not a good practice to use $data = json_decode(file_get_contents('php://input'), true);
for input data in Actions. Because like this it is difficult to do unit tests (need to simulate a real http request) and you can't use these Actions in command line scripts.
A better approach is to collect the input data in the controller thanks to Flight::request()->data->getData();
, and then give it as a parameter to the ->execute()
.
It would be then possible to write unit tests for these Actions and to use them in command line scripts.
@pierresh , thanks a lot! I fixed it, and I’ve made some updates as well. If you could check it out and submit a pull request if there are any issues, that would be great. Also, if possible, message me on Telegram so we can talk more about the projects.
Hello,
First of all, thank you for developing and maintaining the Flight framework. It has been incredibly helpful for our projects, and I really appreciate all the work that has gone into it.
I recently created a simple CRUD API project using the Flight framework, which provides a basic structure for new users to quickly set up a PHP application with CRUD operations and database connectivity. The project demonstrates how to use Flight for RESTful API development, making it an ideal learning tool for beginners and a useful starter kit for more experienced developers.
I believe this project could be a valuable addition to the examples section of the Flight documentation. Including it could help new users understand how to implement CRUD operations using Flight and encourage more adoption of the framework.
You can find the project here: https://github.com/soheilkhaledabdi/php-crud-api-flight
I would be grateful if you could consider adding it to the official documentation or examples list.
Thank you for your consideration and for all the great work you continue to do!
Best regards, soheil