Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
107 views

I have a fairly common setup - 2 main models and 1 pivot with additional information regarding their relationship. I'm using Laravel API Resources and they work great, but I can't figure out a way how ...
WellBloud's user avatar
  • 977
0 votes
1 answer
123 views

GET|HEAD blogs ..................................................................................... blog.index › Blog\BlogController@index POST blogs ...............................
Bikash Chowdhury's user avatar
-2 votes
2 answers
304 views

I'm encountering a peculiar issue in my Laravel API setup. I have a resource controller for managing student data, including deletion. When I make a DELETE request to http://127.0.0.1:8000/api/student/...
Redouane's user avatar
1 vote
1 answer
722 views

In resource file app/Http/Resources/PostResource.php I use method : <?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\JsonResource; class PostResource extends JsonResource { ...
Petro Gromovo's user avatar
1 vote
2 answers
900 views

I wonder what are the best practices that the community have about the architecture of Laravel's Resources. I started using it to avoid sending unnecessary data to certain routes of the API. I ...
Enzo's user avatar
  • 245
0 votes
3 answers
2k views

I am using a Laravel Resource to return my object. The object has optional relationships. My Resource code so far is below and is working as expected: public function toArray(Request $request): array {...
BobbyP's user avatar
  • 2,327
0 votes
1 answer
136 views

In PostCrudRepository class I read mediaProps from other class and write as Attribute: public function get(int $id): Post { $post = Post::getById($id)->firstOrFail(); $mediaStorage= App::...
Petro Gromovo's user avatar
0 votes
1 answer
821 views

I am trying to build a laravel api route to return users data. I got some data stored in txt file. To avoid accessing txt many times, the txt file is read in controller but not in resource. However, ...
Kenzo's user avatar
  • 49
1 vote
0 answers
554 views

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 $...
user3125758's user avatar
0 votes
2 answers
911 views

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. ...
zohrehda's user avatar
  • 690
1 vote
0 answers
737 views

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 ...
Masum Rahman Hasan's user avatar
-2 votes
1 answer
540 views

in laravel 9 , what is the difference between Route::resource('/blog',[PostController::class); and Route::get('/blog',[PostController::class,'index']); ?
Lab Devices's user avatar
1 vote
0 answers
33 views

I use resources on api site to extend data(labels, formatting, related data ...). But when I used ItemResource writing into redis : $activeItems = Item::with('creator')->getByPublished(true)->...
Petro Gromovo's user avatar
1 vote
2 answers
2k views

I am building an API using Resources. I have a Product (Chocolate Cake) that can be linked to a Property (Allergies) that has Properties_property (Glutten) that need to be shown in different orders ...
St. Jan's user avatar
  • 206
1 vote
1 answer
58 views

I am looking for a way that my ProductResource Collection will only include products with active prices. In my routes/api.php am using a Collection as so: Route::get('/product', function (Request $...
St. Jan's user avatar
  • 206
1 vote
2 answers
989 views

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 ...
schutte's user avatar
  • 2,176
0 votes
1 answer
1k views

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 ...
Hooman Limouee's user avatar
0 votes
1 answer
1k views

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:...
Bruno Francisco's user avatar
1 vote
1 answer
891 views

I have a resource controller in my Laravel app, where all resource functions are placed. So far I have the creation and store functions working fine, but it falls on edit() and update(). As far as I ...
Adnan Ali's user avatar
1 vote
2 answers
2k views

I've got a Category resource that looks like this: <?php namespace Domain\Category\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; class ...
MrCujo's user avatar
  • 1,393
0 votes
1 answer
5k views

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 ...
MrCujo's user avatar
  • 1,393
2 votes
1 answer
224 views

As one can read in the Laravel documentation, the following warning is stated: The mergeWhen method should not be used within arrays that mix string and numeric keys. Furthermore, it should not be ...
Robin Bastiaan's user avatar
1 vote
2 answers
1k views

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 ...
Unkown Kid's user avatar
0 votes
1 answer
131 views

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's user avatar
  • 3,309
0 votes
1 answer
97 views

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) -&...
mstdmstd's user avatar
  • 3,309
1 vote
1 answer
515 views

I have two models related to each other with a one-to-one relationship. Model A belongs to model B and when an instance of model B is returned to the frontend, the Resource of the model B includes the ...
Wesley Gonçalves's user avatar
0 votes
2 answers
16k views

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 ...
mnlixk's user avatar
  • 21
0 votes
1 answer
550 views

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 ...
fanaliya's user avatar
3 votes
0 answers
356 views

I am new to Laravel. I am currently building a resource. I was just wondering what is the purpose of passing in the $request object if we use the $this variable when using resources. Below is an ...
json2021's user avatar
  • 2,437
0 votes
1 answer
340 views

I am creating an API using Laravel. I created a table called transaction. I also created a resource called transactionresource. I want to change the id column to be the key column in the API, and I ...
etranz's user avatar
  • 1,313
0 votes
1 answer
1k views

I have 3 tables business, service , service_venues. I need services of business having service_name = $search and and get venues of selected services. I am using services and resources method. When ...
Jyothi's user avatar
  • 73
0 votes
1 answer
574 views

I'm fetching data to paginate but pagination is not working, the fetch response is added below, if I return the query relation it retrieves correct data but when I pass it to the custom response ...
swatantra's user avatar
  • 493
1 vote
2 answers
5k views

So I am trying to control output utilizing resources as I was told it's the best way to model the data for api output. Customer Model public function invoices () { return $this->hasMany('\...
GrafixMastaMD's user avatar
1 vote
0 answers
382 views

I use laravel 8 & have 3 table: Products, ProductPrice & ProductsPublisher: this is my Products model for this relationship: public function lastPrice(){ return $this->hasMany(...
Soroush Tayyebi's user avatar
2 votes
1 answer
1k views

I have a custom attribute that calculates the squad name (to make our frontend team lives easier). This requires a relation to be loaded and even if the attribute is not being called/asked (this ...
Wanjia's user avatar
  • 817
0 votes
1 answer
1k views

PHP 7.4.16 & Laravel 8.61 I have the following code in my Resource: $arr = ['id' => $this->id, 'associations' => (object)[]]; foreach ($tas as $ta) { $ta_id = $ta->id; ...
Inigo EC's user avatar
  • 2,338
0 votes
1 answer
139 views

I have two models, User and Comment, Each User can have multiple Comment, I can call paginate(3) on User and get 3 User in output per page but I need same thing as User for comments in UserCollection. ...
mohammad's user avatar
1 vote
1 answer
2k views

I have come across a solution that filters fields from a resource collection in the Controller CompanyController.php E.g The code below returns all the values except company_logo CompanyResource::...
Lehlohonolo Motsoeneng's user avatar
1 vote
1 answer
265 views

This is my first time posting here so please pardon my errors: I have a search functionality whose route is: Route::get('/search', 'SearchController@index'); Currently, I have an eloquent ...
Evidence Ekanem's user avatar
-1 votes
1 answer
213 views

@foreach($products as $product) <tr> <td>{{ $product->id }}</td> <td>{{ $product->name }}</td> <td>{{ $product->job_category }}&...
John Kyei's user avatar
2 votes
1 answer
3k views

In lumen 8 app I use resources and reading here https://laravel.com/docs/8.x/eloquent-resources I try to use “with” method, as I want to add some meta data to any request and I have no this meta data ...
Petro Gromovo's user avatar
1 vote
2 answers
6k views

I used laravel resources for my api responses and added paginate method. Upon using paginate method I always get a result like this where laravel by default gives three keys namely "data", &...
Mostain ahmed's user avatar
0 votes
1 answer
24k views

I am working with laravel API and using model relationship and resource to get data, I don't know where is the problem that it gives such kind of error, I searched and tried the solutions, but the ...
Zia Yamin's user avatar
  • 1,026
0 votes
0 answers
3k views

<?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json\ResourceCollection; class LanguageCollection extends ResourceCollection { public $collects = ...
Ask17's user avatar
  • 82
8 votes
8 answers
9k views

Laravel default paginate gave me the response with default format for pagination, but I want to remove links in the meta object at the page response I used below code to fetch the page data: public ...
mohammad nabipour's user avatar
0 votes
1 answer
2k views

I'm using the following resource using shallow nesting Route::resource('organizations.emaildomains', 'OrganizationEmailDomainController', ['except' => ['show']])->shallow(); Got the following ...
Tiago Peres's user avatar
  • 15.9k
0 votes
1 answer
962 views

I have two resources Organizations OrganizationUsers (which has FK to Users on user_id) The User model class User extends Authenticatable { use Notifiable; /** * The attributes that ...
Tiago Peres's user avatar
  • 15.9k
0 votes
1 answer
2k views

I am writing because I have spent hours of testing looking for a solution to a problem and I still have not found how to solve it. I am using Spatie Laravel Permission and it happens that I have 3 ...
leo95batista's user avatar
0 votes
0 answers
4k views

I have a problem when returning an api resource. I am using Spatie Laravel Permission. It happens that in my particular case I am trying to return an api resource with the details of the user and next ...
leo95batista's user avatar
1 vote
1 answer
2k views

When returning a model using resource created_at and updated_at casting is working fine, but when i modify the toArray() function the casting is not working ! in my model : protected $casts = [ ...
derar sattouf's user avatar