PHP code example of achrafbardan / simple-resources
1. Go to this page and download the library: Download achrafbardan/simple-resources library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
achrafbardan / simple-resources example snippets
return [
"model_namespace" => "App\\Models",
"resource_namespace" => "App\\Http\\Resources",
/**
* When this is set to false, you have to add the \AchrafBardan\SimpleResources\Contracts\HasResource interface to your models.
* When set to true you can still optionally add the interface to your models, this interface will than be used instead of the guesser.
*/
"guess_resource" => true
];
use AchrafBardan\SimpleResources\ResourceFactory;
...
$resource = ResourceFactory::make($model);
return response()->json($resource);
use function AchrafBardan\SimpleResources\resource;
...
$resource = resource($model);
return response()->json($resource);
// App/Http/Resources/TestResource.php
...
class TestResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'child' => resource($this->whenLoaded('child'))
];
}
}