PHP code example of dandoetech / laravel-generic-api
1. Go to this page and download the library: Download dandoetech/laravel-generic-api 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/ */
dandoetech / laravel-generic-api example snippets
class ProductResource extends Resource implements HasEloquentModel, HasPolicy
{
public function model(): string { return \App\Models\Product::class; }
public function policy(): string { return \App\Policies\ProductPolicy::class; }
protected function define(ResourceBuilder $b): void
{
$b->key('product')
->label('Product')
->timestamps()
->field('name', FieldType::String, nullable: false, rules: ['ory_name'])
->sortable(['name', 'price', 'created_at', 'orders_count'])
->action('create')
->action('update')
->action('delete');
}
}