0

In Laravel 5.5+, we can use API resource to format our API response in a way we want. I want to create API resource in Laravel 5.4 project which I can't upgrade to 5.5. Is there any way to use API resource in Laravel 5.4?

If not, what is the best way to format response and how to properly format responses while creating an API with Laravel? What are the tips and best practices to create API in Laravel version 5.4, 5.3, 5.2 etc?

2
  • why you dont upgrade the app? and get all the new features. laravel.com/docs/5.5/upgrade Commented Mar 30, 2018 at 1:45
  • Depending on the complexity of his/her app it's not always the right thing to do - especially if it's already in production Commented Mar 30, 2018 at 9:49

1 Answer 1

3

I would highly recommend using Fractal by the League of PHP: http://fractal.thephpleague.com/

The concept is the same (typically a "resource" is called a transformer). They tackle both single items and collections and act as a simplification layer between the actual data and what you want presented through your endpoint.

I have been using this in 5.0 through to 5.4 without issue.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, @Chris, I saw fractal and it's what I am looking for. I think!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.