Skip to content

Instantly share code, notes, and snippets.

@siljanoskam
Created April 25, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siljanoskam/e0e30203405aab2c683bd233b50e2f4b to your computer and use it in GitHub Desktop.
Save siljanoskam/e0e30203405aab2c683bd233b50e2f4b to your computer and use it in GitHub Desktop.
Resources
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class Task extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'date' => $this->date,
'status' => $this->status,
'user_id' => $this->user_id
];
}
}
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class User extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment