ÿØÿà JFIF ÿá Exif MM * ÿÛ C
Server IP : 199.250.214.225 / Your IP : 3.139.82.131 Web Server : Apache System : Linux vps64074.inmotionhosting.com 3.10.0-1160.105.1.vz7.214.3 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : nicngo5 ( 1001) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /home/nicngo5/laravelvue/vendor/laravel/framework/src/Illuminate/Http/Resources/Json/ |
Upload File : |
<?php namespace Illuminate\Http\Resources\Json; use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Contracts\Support\Responsable; class ResourceResponse implements Responsable { /** * The underlying resource. * * @var mixed */ public $resource; /** * Create a new resource response. * * @param mixed $resource * @return void */ public function __construct($resource) { $this->resource = $resource; } /** * Create an HTTP response that represents the object. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\JsonResponse */ public function toResponse($request) { return tap(response()->json( $this->wrap( $this->resource->resolve($request), $this->resource->with($request), $this->resource->additional ), $this->calculateStatus() ), function ($response) use ($request) { $response->original = $this->resource->resource; $this->resource->withResponse($request, $response); }); } /** * Wrap the given data if necessary. * * @param array $data * @param array $with * @param array $additional * @return array */ protected function wrap($data, $with = [], $additional = []) { if ($data instanceof Collection) { $data = $data->all(); } if ($this->haveDefaultWrapperAndDataIsUnwrapped($data)) { $data = [$this->wrapper() => $data]; } elseif ($this->haveAdditionalInformationAndDataIsUnwrapped($data, $with, $additional)) { $data = [($this->wrapper() ?? 'data') => $data]; } return array_merge_recursive($data, $with, $additional); } /** * Determine if we have a default wrapper and the given data is unwrapped. * * @param array $data * @return bool */ protected function haveDefaultWrapperAndDataIsUnwrapped($data) { return $this->wrapper() && ! array_key_exists($this->wrapper(), $data); } /** * Determine if "with" data has been added and our data is unwrapped. * * @param array $data * @param array $with * @param array $additional * @return bool */ protected function haveAdditionalInformationAndDataIsUnwrapped($data, $with, $additional) { return (! empty($with) || ! empty($additional)) && (! $this->wrapper() || ! array_key_exists($this->wrapper(), $data)); } /** * Get the default data wrapper for the resource. * * @return string */ protected function wrapper() { return get_class($this->resource)::$wrap; } /** * Calculate the appropriate status code for the response. * * @return int */ protected function calculateStatus() { return $this->resource->resource instanceof Model && $this->resource->resource->wasRecentlyCreated ? 201 : 200; } }