PHP code example of feldoe / laravel-resource-index

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

    

feldoe / laravel-resource-index example snippets


use Atx\ResourceIndex\Contracts\ResourceIndex;
use Illuminate\Routing\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class Index extends Controller
{
    public function __invoke(Request $request, ResourceIndex $service): JsonResponse
    {
        return $service->from(MyModel::class, MyModelResource::class)
            ->processRequest(
                $request,
                // Filterable
                [
                    'filterable_column',
                ],
                // Searchable
                [
                    'searchable_column',
                ],
                // Sortable
                [
                    'sortable_column',
                ]
            )
            ->response();
    }
}