J
J
jazzus2018-12-06 04:25:28
Laravel
jazzus, 2018-12-06 04:25:28

How to remove fields from Laravel Resource related relationships?

While I understand what server rendering is, I wanted to know - how can I hide fields from models in relations if I use json from Laravel? Those. I form json through Laravel Resource and there you can specify all the fields of the table. But if I need to get data from related type models in Vue, {{user.group.category.name}}then in the Laravel controller I need to make a type request, $users->with('group.category');(and if for $user in the UserResource file I can specify only the fields I need like user.name or user.lastname (and all the rest will be frame) then for the associated models, laravel generates json with all fields. Is it possible to also set only the required fields for such relationships?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2018-12-06
@jazzus

Make a resource for the relation inside the main resource

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question