with() 공개 메소드

public with ( $relationships )
예제 #1
0
 public function testCanMergeWithAnotherResource()
 {
     $post1 = (object) ['id' => '123', 'foo' => 'bar', 'comments' => [1]];
     $post2 = (object) ['id' => '123', 'baz' => 'qux', 'comments' => [1, 2]];
     $resource1 = new Resource($post1, new PostSerializer4());
     $resource2 = new Resource($post2, new PostSerializer4());
     $resource1->with(['comments']);
     $resource2->with(['comments']);
     $resource1->merge($resource2);
     $this->assertEquals(['type' => 'posts', 'id' => '123', 'attributes' => ['baz' => 'qux', 'foo' => 'bar'], 'relationships' => ['comments' => ['data' => [['type' => 'comments', 'id' => '1'], ['type' => 'comments', 'id' => '2']]]]], $resource1->toArray());
 }
예제 #2
0
 /**
  * Get the result of an API request to show the current user.
  *
  * @return array
  */
 protected function getUserDocument(Request $request)
 {
     $actor = $request->getAttribute('actor');
     $this->userSerializer->setActor($actor);
     $resource = new Resource($actor, $this->userSerializer);
     $document = new Document($resource->with('groups'));
     return $document->toArray();
 }