@@ 278-293 (lines=16) @@ | ||
275 | * |
|
276 | * @return object|null The related resource if found else null |
|
277 | */ |
|
278 | public function getRelatedResourceReference( |
|
279 | ResourceSet $sourceResourceSet, |
|
280 | $sourceEntityInstance, |
|
281 | ResourceSet $targetResourceSet, |
|
282 | ResourceProperty $targetProperty |
|
283 | ) { |
|
284 | if (!($sourceEntityInstance instanceof Model)) { |
|
285 | throw new InvalidArgumentException('Source entity must be an Eloquent model.'); |
|
286 | } |
|
287 | $this->checkSourceInstance($sourceEntityInstance); |
|
288 | ||
289 | $this->checkAuth($sourceEntityInstance); |
|
290 | ||
291 | $propertyName = $targetProperty->getName(); |
|
292 | return $sourceEntityInstance->$propertyName; |
|
293 | } |
|
294 | ||
295 | /** |
|
296 | * Gets a related entity instance from an entity set identified by a key |
|
@@ 307-319 (lines=13) @@ | ||
304 | * |
|
305 | * @return object|null Returns entity instance if found else null |
|
306 | */ |
|
307 | public function getResourceFromRelatedResourceSet( |
|
308 | ResourceSet $sourceResourceSet, |
|
309 | $sourceEntityInstance, |
|
310 | ResourceSet $targetResourceSet, |
|
311 | ResourceProperty $targetProperty, |
|
312 | KeyDescriptor $keyDescriptor |
|
313 | ) { |
|
314 | if (!($sourceEntityInstance instanceof Model)) { |
|
315 | throw new InvalidArgumentException('Source entity must be an Eloquent model.'); |
|
316 | } |
|
317 | $propertyName = $targetProperty->getName(); |
|
318 | return $this->getResource(null, $keyDescriptor, [], $sourceEntityInstance->$propertyName); |
|
319 | } |
|
320 | ||
321 | ||
322 | /** |