Questions tagged [laravel-resource]

For more information visit Laravel resources reference.

107 questions
0
votes
0 answers

Eloquent Resource with two possible pivot tables - elegant way to return values

I got a resource that comes with two possible pivots. Now I'd like to add values depending on which pivot is loaded. This is how I am doing it at the moment:
SPQRInc
  • 162
  • 4
  • 23
  • 64
0
votes
2 answers

Format field data as dictionary using Laravel Resources

I need to format the data field of the Laravel API response in order to make it a dictionary. I am using Laravel Resources. At the moment the result is { "data": [ { "id": 1, "title": "Qui enim rerum." }, …
0
votes
1 answer

add status and message keys to the resource json response in laravel

I am using a resource in laravel 5.5 from which I am returning the collection in my controller but I am unable to customize it's output json. I want to add status and message key to it's json output. I have tried to modify the toArray method but…
Uzair
  • 186
  • 1
  • 11
0
votes
1 answer

Remove null from Laravel resources collection

I build a Laravel API using resources. It return a collection plus some extra meta data. I want to remove the null item(s) without losing my formatted JSON response. Note: I tried filter method but it removed "data" and "extra_meta" from the JSON…
Mano
  • 55
  • 7
0
votes
0 answers

Laravel resource ignoring given fields

I'm trying to convert a given API response in something easy to work with. This is what I have so far: Controller: public function drive() { $optParams = [ 'corpora' => 'drive', 'driveId' => env('GOOGLE_DRIVE_ID'), …
Goowik
  • 782
  • 11
  • 36
0
votes
2 answers

Unable to Retrieve Old Data in Edit Form in Laravel

I want to get data of that id when pressed the edit button. My all fields remain empty. I'm using same page for Create & Edit. Update Function public function update(Request $request) { $user = User::findOrFail($request->user_id); …
Abdul Rehman
  • 159
  • 1
  • 2
  • 18
0
votes
1 answer

changing key names when leveraging laravel resources to return API data

So I am currently building out an API and see that laravel has added an API resource which I am assuming is in lieu of something like fractal? However running into an issue where when I go to return a collection using the XyzCollection resource I…
Citti
  • 423
  • 1
  • 6
  • 23
0
votes
1 answer

Saving foreign key value in relevant table - Laravel Resource Control

I have 2 tables: Manufacturers and Brands. Manufacturers: fields : id and manufacturer Brands: fields : many other fields with 'manufacturer_id' field which indexes "Manufacturers" table's 'id'. I have a select box which supposed to load…
0
votes
1 answer

Laravel JsonResource: array_merge_recursive(): Argument #2 is not an array

I have a JsonResource of Post that should return a single post. But after joining some other data I get this error: array_merge_recursive(): Argument #2 is not an array. This does not work: /** * Display the specified resource. * * @param int …
0
votes
1 answer

Laravel Resource

I have multiple resources and mostly resource content few fields that are same for all other resource and it's very difficult to modify all the resource in case I need to update/add key/value in the resource. Is there any way that I can create one…
-1
votes
1 answer

Route [$products.edit] not defined

@foreach($products as $product) {{ $product->id }} {{ $product->name }} {{ $product->job_category }} {{ $product->purpose }} {{ $product->region }} …
-1
votes
2 answers

Laravel Resources Returning null

Returning laravel resource is giving null but the database have files. here is my resource class class UsersResource extends JsonResource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request …
Khal
  • 219
  • 5
  • 19
-1
votes
2 answers

Storing data with Eloquent Model not working, Call to undefined method

I want to make Restful API with Laravel and I want to write a script that is going through the CSV file, and firstly POST Animal, then get Animal ID from response, and POST AnimalDate, but It's not working as I want and I'm getting this following…
VladoS24
  • 47
  • 8
-1
votes
2 answers

The implicit binding in laravel (5.6) returt a empty object

i'm trying to use the method 'show' in a controller but when it return a empty object. Since this view: @foreach ($usuarios as $usuario2)

{{$usuario2->nombre}}

ver…