1. Go to this page and download the library: Download aqjw/resource-typeable 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/ */
aqjw / resource-typeable example snippets
use Aqjw\ResourceTypeable\ResourceTypeable;
...
class ProductResource extends JsonResource
{
use ResourceTypeable;
...
...
class ProductController extends Controller
{
...
public function index()
{
$products = Product::paginate(9);
return new ProductCollection($products); // will return tiny resource type
// or
return ProductCollection::make($products); // will return tiny resource type
// or
return ProductResource::collectionType('full', $products); // will return full resource type
}
...
...
class ProductController extends Controller
{
...
public function show(Product $product)
{
return ProductResource::makeType('full', $product);
}
...
use Aqjw\ResourceTypeable\ResourceTypeable;
...
class ProductResource extends JsonResource
{
use ResourceTypeable;
/**
* Resource type
*
* @var string
*/
protected static $resource_type = 'full';
...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.