PHP code example of kayrunm / polybind

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

    

kayrunm / polybind example snippets


'providers' => [
    // ...
    Kayrunm\Polybind\PolybindServiceProvider::class,
],

protected $middlewareAliases = [
    // ...
    'polybind' => Kayrunm\Polybind\Polybind::class
];

// routes/web.php

Route::get('/{model_type}/{model_id}', [MyController::class, 'show'])->middleware('polybind');

// MyController.php

public function show($model)
{
    return response()->json($model);
}

// MyController.php

public function show(HasAuthor $model)
{
    return response()->json($model);
}

// MyController.php

public function show(Post|Comment $model)
{
    return response()->json($model);
}

// routes/web.php

Route::get('/{author_type}/{author_uuid}', function ($author) {
    return response()->json($author);
})->middleware('polybind:author_type,author_uuid,author');

protected $middlewareGroups = [
    'web' => [
        // ...
        \Kayrunm\Polybind\Polybind::class,    
    ],
    
    'api' => [
        // ...
        \Kayrunm\Polybind\Polybind::class,    
    ],
];
bash
php artisan vendor:publish --provider="Kayrunm\Polybind\PolybindServiceProvider"