Skip to main content

Protect Your Inertia Data with API Resources

Premium
3 min read

In this lesson, I want to show that you can still use API resources or Eloquent API resources to transform that data, although you don't use API directly.


Why Use API Resources?

For example, in the initial project, using Vue.js with API, the content was stripped to 50 symbols and the created at date was formatted as a date time string. For that, the API Eloquent resources were used. API resources can also be used with Inertia.

Why do you need to do that? There are two reasons:

  1. Format the data however you want.
  2. Limiting data that is passed to the front-end.

Keep in mind that all that data is passed to...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

LS
Luis Scura ✓ Link copied!

If don't have the Api directory inside the controllers because I am not building an API. Is still recommended to create it for the api resources and to customize the pass values to Inertia? Or just use the get->fields?

P
porrapat ✓ Link copied!

If you mean API resource, It is not necessary but it is good to do. Because you can specify column instead of using Post::all();

For others, I don't know.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.