1. Go to this page and download the library: Download sofronz/elysia 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/ */
use Sofronz\Elysia\Facades\Filter;
use App\Models\User;
public function index()
{
$filteredUsers = Filter::model('user')->apply(User::query())->get();
return response()->json($filteredUsers);
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class YourModel extends Model
{
/**
* Map query string parameters to model attributes.
*
* @return array
*/
public static function getQueryStringMapping(): array
{
return [
'name_search' => 'name', // custom query parameter `name_search` maps to `name` field
'email_like' => 'email', // custom query parameter `email_like` maps to `email` field
'status_in' => 'status', // custom query parameter `status_in` maps to `status` field
'created_at_sort' => 'created_at', // custom query parameter `created_at_sort` maps to `created_at` field
];
}
}