Questions tagged [laravel-resource]

For more information visit Laravel resources reference.

107 questions
0
votes
0 answers

Laravel Resource conditional fields

In Laravel I'm generating serialized responses using resource classes. I have the following resources: JobOffer and Business. Here is JobOfferResource::toArray method public function toArray(Request $request): array { return [ 'id' =>…
0
votes
2 answers

Laravel resource performance

I'm using laravel framework and now I'm thinking that if laravel resource reduce the performance? Because it at first select all columns (select * from TABLE) then put the result in loop of resource. So does this loop slow down the speed? Actually…
zohrehda
  • 625
  • 5
  • 10
0
votes
0 answers

Laravel Api resource not returning the data specified on the resource

In controller I have added a login method and when the login will success it will return the data only those which are included in a resource. But it is returning all data. It was working till morning but now it's not. In my controller I have done…
0
votes
0 answers

Associate method in laravel 8

I'm new to laravel and I'm making a small api with just two tables to start. I have roles and people. I want to assign a role to a person from the store method but I don't understand how associate() works or how to implement it in the store method,…
ari127
  • 103
  • 3
0
votes
0 answers

Returning Pivot table data in Laravel 9 Resource (Building an API)

I'm trying to build an API in Laravel 9 and want data from a pivot table. I want to retrieve all instances, whether they have sessions assigned to them or not, and display the sessions where relevant. I currently have a table of instances and a…
0
votes
1 answer

How to fix Laravel resource is not working properly in blade view?

I'm confused why casted props are inaccessible in the blade file. When I try to check it in the controller its showing properly. Here's the JSON shown in the browser: return $users; (here status is string) But when I tried to show it in the view,…
schutte
  • 1,949
  • 7
  • 25
  • 45
0
votes
1 answer

Single api call vs multiple calls per page in SPA

I'm totally new to SPAs so I need to find the best approach for loading data in front-end. I'm using React and Next for the front-end and Laravel for the back-end. Currently I am making only one request per page to get required data. But the problem…
Hooman Limouee
  • 1,143
  • 2
  • 21
  • 43
0
votes
1 answer

how to use collection on same model laravel resources

We are currently developing a feature in codotto.com where a user can comment on an IT meetup. Each comment can have an answer to it. We are only allowing for one-level deep answers, so something like: - Comment 1 - Answer to comment 1 - Answer…
Bruno Francisco
  • 3,841
  • 4
  • 31
  • 61
0
votes
1 answer

Laravel: Get the correct value of an enum field on a resource class

I'm using PHP8.1 and Laravel 9 for a project in which I've got the following enum: enum OrderStatuses : string { case New = 'new'; case Pending = 'pending'; case Canceled = 'canceled'; case Paid =…
MrCujo
  • 1,218
  • 3
  • 31
  • 56
0
votes
1 answer

Conditionally add additional attribute to resource

I have the following resource being returned: { "id": "b93244c5-0c1e-4388-bd61-fd577b5c7c57", "state": 3, "createdAt": "2022-08-03T13:58:27.000000Z", "attendee": { "id": "5a0f730a-dcc7-4937-9a6a-bb9fe4a9285c", "about": "...", …
Bruno Francisco
  • 3,841
  • 4
  • 31
  • 61
0
votes
2 answers

Laravel Different Views Folder

I have downloaded a project and I noticed that the project use views from different directory not the usual directory which are \resources\views but instead it create a new folder name themes and insert all the views in…
Unkown Kid
  • 135
  • 1
  • 1
  • 8
0
votes
1 answer

Why using additive paramerer in Resource collection raised error?

In laravel 9 app I want to add additive paramerer into Resource and looking at this Laravel 5.6 - Pass additional parameters to API Resource? branch I remade in app/Http/Resources/CurrencyResource.php :
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
0
votes
1 answer

How to add image props array in resouce?

In laravel 9 I want to join $CMSItem object and properties of related image(I use spatie/laravel-medialibrary) in one resource, having in control : $CMSItem = CMSItem ::getById($cms_item_id) ->with('author') ->first(); $CMSItemImage =…
mstdmstd
  • 2,195
  • 17
  • 63
  • 140
0
votes
1 answer

Laravel API resource paginate sub data

I'm trying to understand Laravel API resource and would like to know how I could use pagination with a subset of my data. For example: I have a book model and to return all the books available I could write: return…
mnlixk
  • 11
  • 1
  • 6
0
votes
1 answer

Laravel groupBy in collection not working

I am trying to group the result with the status name inside. I am not doing groupBy after collection because I am using resource to return data, there are some logic inside resource. Grouping data before using get() gives an error because it needs…