laravel-responder
laravel-responder copied to clipboard
Support Laravel 5.5 resources
Hi @flugger,
Have you seen https://laravel.com/docs/5.5/eloquent-resources? If so, would you consider to release a new package version that leverages that new feature?
Cheers, Evgenii
Hey!
Yes, I've been looking into the 5.5 resources and feel they're a step in the right direction, however, they currently don't provide the same feature-set as Fractal. The only really unique feature of the 5.5 resources is the conditional attributes and I will be looking into supporting this in the near future.
I've been tinkering with ways to combine them to get the best of both worlds, but they don't really play well together and it would probably be more efficient to just use the 5.5 resources and rewrite some of Fractal's features on top of it. However, I feel like this package is in a really good state after a recent major rewrite and I'm thinking I'm gonna give the 5.5 resources some time to adopt before I head into a new rewrite.
One crazy idea that just crossed my mind though; I suppose I could rename Transformer to Resource and move it into the Http folder for a 3.0
release to make it feel more like 5.5. But the 'resource' name do kind of collides with Fractal's own concept of a resource..
Sounds reasonable! Let it steep for some time... The one thing I'm afraid of is that you can keep up with the laravel features like conditional fields but I'm pretty sure there will be more features introduced with time and you will have to basically duplicate the code...
I'll leave this issue open and think some more about how to best support resource objects.
Hi @flugger,
Is there any update on this? It would be awesome to make use of eloquent resource functions.
I'm currently building a laravel application where I'm using eloquent resources, in an effort to learn more about them and see how they would fit into this package. So I'm definitely keen on finding a solution for this, but I'm afraid it requires a major rewrite. I'll keep you updated :)
@nasyrov @mrajabtech I have some updates I would like to share - the last couple of weeks I've been hard at work rewriting the package to support API resources and discard Fractal altogether. This has allowed me to simplify the code a lot and I believe the package has a clearer focus and is easier to use while keeping the core of the package the same. Most of the open issues will be solved with this release. If anyone has any requests for the new version, please let me know. I expect to have it all ready before 2020 🙂
@flugger Fantastic!! Can't wait to play with the new release :100:
Hi @flugger sounds exciting!
Hi @flugger, do you think we are close to see the eloquent resources switch?
I see there is a branch feature/api-resources
, is it stable enough to use it in my application?
@iamroi Hi, we are close indeed! Things have slowed down a bit the past month, but I'll put some effort into finishing the version soon :)
I don't think the branch is stable enough to use in production yet, but would love some feedback, so feel free to use it and tell me what you think. It's a complete rewrite of the package and I've been a bit hesitant to release it as I want to make sure people will be happy with the changes.
Hey @flugger great looking package - thanks! I've been looking for something that incorporates Laravel resources.
I've just tried to install what will be v4.0 but i'm getting a class not found error for Flugg\Responder\Http\Responses\Decorators\StatusCodeDecorator
Output
Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals
- Installing flugger/laravel-responder (dev-feature/api-resources 8e92c02): Loading from cache Writing lock file Generating optimized autoload files composer/package-versions-deprecated: Generating version class... composer/package-versions-deprecated: ...done generating version class Illuminate\Foundation\ComposerScripts::postAutoloadDump @php artisan package:discover --ansi PHP Fatal error: Uncaught Error: Class 'Flugg\Responder\Http\Responses\Decorators\StatusCodeDecorator' not found in /home/aubrey/development/concord/vendor/flugger/laravel-responder/src/ResponderServiceProvider.php:66 Stack trace: #0 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Container/Container.php(801): Flugg\Responder\ResponderServiceProvider->Flugg\Responder{closure}() #1 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Container/Container.php(687): Illuminate\Container\Container->build() #2 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve() #3 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Foundation\Application->resolve() #4 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\Container\Container->make() #5 /home/aubrey/development/concord/ve in /home/aubrey/development/concord/vendor/flugger/laravel-responder/src/ResponderServiceProvider.php on line 66 PHP Fatal error: Uncaught Error: Class 'Flugg\Responder\Http\Responses\Decorators\StatusCodeDecorator' not found in /home/aubrey/development/concord/vendor/flugger/laravel-responder/src/ResponderServiceProvider.php:66 Stack trace: #0 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Container/Container.php(801): Flugg\Responder\ResponderServiceProvider->Flugg\Responder{closure}() #1 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Container/Container.php(687): Illuminate\Container\Container->build() #2 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve() #3 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Foundation\Application->resolve() #4 /home/aubrey/development/concord/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\Container\Container->make() #5 /home/aubrey/development/concord/ve in /home/aubrey/development/concord/vendor/flugger/laravel-responder/src/ResponderServiceProvider.php on line 66 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
Hey @iamroi and @aubreychiduku , sorry for the delay on the new version and the problems in the "alpha" version - have been some busy months and want to get it perfect before I release it. Have had quite some time to work on it the couple past weeks and I must say, the end result is looking better than first anticipated. I'm very happy with the direction the package is heading and it should be ready for release sometime soon. I'll see if I can push the latest changes once I hit the next milestone and the tests pass.
With that said, I'd love to share some of the highlights of the new version:
-
Formatters: Since Fractal has been dropped in favour of API resources I wanted to keep the resources as a replacement for Fractal's transformers and introduce a new concept to replace Fractal's serializers; Formatters. The package will ship with two formatters out of the box:
SimpleFormatter
, which looks very similiar to the default serializer today, and aJsonApiFormatter
. I know a lot of people use Fractal to work with JSON API and I don't want to leave them in the dark with the new version. One difference between Fractal's serializers and formatters is that formatters also defines a format for error responses. It's also much easier to build your own formatters than it is to build Fractal serializers. (You only have two methods:success
anderror
to format each response respectively). -
Normalizers: One of the big selling points of the package is that you can send in many different types of data to a success response (arrays, models, collections, paginators, query builders etc), however, the supported types were hardcoded in the package. The new version ships with a new concept of a
Normalizer
, which normalizes a type to an understandable format. The normalizers are configurable, meaning you can easily extend the package to accept new type of data structures. - Adapters: The package has always relied on Fractal's adapters for handling paginators, which allows for supporting different types of paginators. Now that we no longer rely on Fractal the package has its own set of adapters. In addition to having adapters for paginators and cursor paginators, the new version also has support for validator adapters.
- Improved exception handler: The package always had its own exception handler logic you could apply to automatically catch exceptions and convert them to error responses. However, with the new version, I've found a clever way to decorate the app's exception handler using the the service container meaning you wont even need to make any modifications to your exception handler. Just install the package and you're set to go!
- Testing macros: The package has had testing utilities to assist with testing responses, but they're currently outdated and requires the https://github.com/laravel/browser-kit-testing package to work. The new version includes new testing helpers and works out of the box without using a trait.
And all of this with the same API as before and a 40% reduction of code allowing for a more concise code base. It also currently has 100% test coverage. Hope you're all as excited as I am!
Omg this is soo exciting!! Thank you for finding time to work on this in your busy schedule. I can't wait to try the new features :) Hope I can contribute in some way!
Hello!
Found this "issue" and wondering is the new version still alive? :)
Hi @Hesesses,
I've been eagerly awaiting its release for quite some time. However, since I'm not actively using PHP in my day-to-day work, finding the time and motivation to complete the final steps has been challenging. The package is almost finished, and to the best of my knowledge, it should work flawlessly. You can find the code and updated documentation in the api-resources branch. To be transparent, here's the remaining to-do list that I haven't touched in a year or two:
- Write feature tests
- Finalize the documentation
- Implement the new cursor-based pagination introduced in the previous Laravel version (not required for the initial release)
- Release the new version along with detailed release notes 🎉
- Tidy up the repository by closing old issues and performing necessary maintenance
As you can see, the project is nearly complete. However, since it has been a while since I delved into the code, it will take some time to familiarize myself with it again. My plan is to run the new version on a fresh Laravel installation and thoroughly test that everything functions as intended. I welcome any contributions from the community, and I'll make an effort to allocate time soon to address the remaining tasks.
Thanks @flugg for the update.
I'm planning to start a new project in few weeks and I will give a try for the new version. I have never been working with a package, but I will test as much as possible and give feedback 🙏
Do you have any ideas why installing the branch does not work with composer?
composer.json
"flugg/laravel-responder":"dev-feature/api-resources",
...
"repositories": [
{
"type": "vcs",
"url": "https://github.com/flugg/laravel-responder"
}
]
Your requirements could not be resolved to an installable set of packages.
Problem 1 - Root composer.json requires flugg/laravel-responder, it could not be found in any version, there may be a typo in the package name.