-
-
Save uno-de-piera/e6a0f264cd512e7a5ca81577c92ca1c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Resources; | |
use Illuminate\Http\Resources\Json\Resource; | |
class CategoryResource extends Resource | |
{ | |
/** | |
* Transform the resource into an array. | |
* | |
* @param \Illuminate\Http\Request | |
* @return array | |
*/ | |
public function toArray($request) | |
{ | |
return [ | |
'id' => $this->id, | |
'name' => $this->name | |
]; | |
} | |
} | |
<?php | |
namespace App\Http\Resources; | |
use App\Category; | |
use Illuminate\Http\Resources\Json\Resource; | |
class PostResource extends Resource | |
{ | |
/** | |
* Transform the resource into an array. | |
* | |
* @param \Illuminate\Http\Request | |
* @return array | |
*/ | |
public function toArray($request) | |
{ | |
return [ | |
"title" => $this->title, | |
"body" => $this->body, | |
'categories' => CategoryResource::collection($this->categories) | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment