PHP code example of equidna / laravel-toolkit

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

    

equidna / laravel-toolkit example snippets


'providers' => [
    Equidna\Toolkit\Providers\EquidnaLaravelToolkitServiceProvider::class,
],

return [
    'paginator' => [
        'page_items' => 15,
        'strategy' => null, // bind PaginationStrategyInterface to override
    ],
    'route' => [
        'api_matchers' => ['api*', '*-api*'],
        'hook_matchers' => ['hooks/*'],
        'iot_matchers'  => ['iot/*'],
        'json_matchers' => [],
        'detector' => null,           // RouteDetectorInterface
        'request_resolver' => null,   // RequestResolverInterface
    ],
    'responses' => [
        'allowed_headers' => ['Cache-Control', 'Retry-After'],
        'strategies' => [], // console/json/redirect => class names
    ],
];

// In your application's service provider
$this->app->singleton(\Equidna\Toolkit\Contracts\RouteDetectorInterface::class, fn($app) =>
    $app->make(App\Routing\SubdomainRouteDetector::class)
);

$this->app->singleton('equidna.responses.json_strategy', fn($app) =>
    $app->make(App\Http\Responses\AuditJsonResponse::class)
);

use Equidna\Toolkit\Helpers\RouteHelper;

if (RouteHelper::isApi()) { /* ... */ }
if (RouteHelper::wantsJson()) { /* return an API-friendly payload */ }

use Equidna\Toolkit\Helpers\ResponseHelper;

// JSON for API/hook/IoT, redirect with flash for web, text for console
return ResponseHelper::success('Saved', ['id' => $model->id]);

// Custom status and headers (filtered through the allow-list for JSON)
return ResponseHelper::unprocessableEntity(
    message: 'Invalid input',
    errors: ['email' => ['Already taken']],
    headers: ['Retry-After' => '30'],
);

use Equidna\Toolkit\Helpers\PaginatorHelper;

$paginator = PaginatorHelper::buildPaginator($collection, page: 2, items_per_page: 20, set_full_url: true);
PaginatorHelper::appendCleanedRequest($paginator, request());

use Equidna\Toolkit\Traits\Database\HasCompositePrimaryKey;

class UserRole extends Model
{
    use HasCompositePrimaryKey;

    public function getKeyName()
    {
        return ['user_id', 'role_id'];
    }
}