PHP code example of hygo / laravel-api-waypoint

1. Go to this page and download the library: Download hygo/laravel-api-waypoint 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/ */

    

hygo / laravel-api-waypoint example snippets


class ListOrders
{
    use AsAction;

    public function asController(Request $request)
    {
        return QueryBuilder::for(Order::class)
            ->allowedFilters([
                AllowedFilter::exact('status'),
                AllowedFilter::partial('reference'),
                AllowedFilter::partial('customer.name'),
                AllowedFilter::custom('placed_between', new PlacedBetweenFilter),
            ])
            ->allowedSorts(['placed_at', 'total_cents', 'reference'])
            ->defaultSort('-placed_at')
            ->allowedIncludes(['customer', 'lines', 'lines.product'])
            ->allowedFields(['orders.id', 'orders.reference', 'orders.status'])
            ->paginate(min($request->integer('per_page', 15), 100));
    }
}

class ListOrders implements ProvidesWaypointQuery
{
    use AsAction;
    use HasWaypointQuery;

    public static function waypointQuery(): QueryConfig
    {
        return QueryConfig::make()
            ->exactFilter('status', values: OrderStatus::class, multiple: true)
            ->partialFilter('reference')
            ->partialFilter('customer.name', relation: 'customer')
            ->customFilter('placed_between', PlacedBetweenFilter::class, valueHint: 'date_range_csv')
            ->sorts(['placed_at' => 'desc', 'total_cents', 'reference'])
            ->

class ImportOrders implements ProvidesWaypointInput
{
    public static function waypointInput(): ?string
    {
        return ImportOrdersData::class;   // or null: "this endpoint takes no body"
    }
}

#[WaypointEndpoint(summary: 'Refund a paid order', roles: ['admin'])]
#[WaypointResponse(status: 202, transformer: RefundTransformer::class, errors: [409])]
#[WaypointPrecondition('Order must be in the paid state', scenario: 'paid_order')]
class RefundOrder { /* ... */ }

#[WaypointFaker(strategy: 'pattern', pattern: 'ORD-######', 

// bootstrap/app.php, local only
$middleware->api(append: [RecordsWaypointResponses::class]);
dotenv
API_WAYPOINT_ENABLED=true
API_WAYPOINT_SECRET=  # php -r "echo bin2hex(random_bytes(32));"
yaml
- run: php artisan waypoint:check --fail-on-unmapped
- run: php artisan waypoint:check --baseline=storage/api-waypoint-baseline.json
bash
php artisan waypoint:handshake          # human-readable
php artisan waypoint:handshake --json   # for the companion app to consume