PHP code example of tiagomichaelsousa / laravelfilters

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

    

tiagomichaelsousa / laravelfilters example snippets


use tiagomichaelsousa\LaravelFilters\Traits\Filterable;

class User extends Authenticatable
{
    use Filterable;
}

use tiagomichaelsousa\LaravelFilters\QueryFilters;

class UserFilters extends QueryFilters
{
    /**
     * Search all.
     *
     * @param  string  $query
     * @return Builder
     */
    public function search($value = '')
    {
        return $this->builder->where('name', 'like', '%' . $value . '%');
    }
}

/**
 * Search all.
 *
 * @param  string  $query
 * @return Builder
 */
public function search($value = '')
{
    return $this->builder
                ->where('name', 'like', '%' . $value . '%')
                ->orWhere('last_name', 'like', '%' . $value . '%');
}

/**
 * Filter by country.
 *
 * @param  string $country
 * @return Builder
 */
public function country($country)
    {
    return $this->builder->whereHas('address', function ($query) use ($country) {
        $query->where('country_code', $country);
    });
}

class UserControllerAPI extends Controller
{
    /**
     * Display a listing of the users.
     *
     * @param  \App\Filters\UserFilters  $filters
     * @return \App\Http\Resources\Collections\UserCollection
     */
    public function index(UserFilters $filters)
    {
        $users = User::filter($filters)->resolve();

        return new UserCollection($users);
    }

class MeetingUsersControllerAPI extends Controller
{
    /**
     * Display a listing of the users from a meeting.
     *
     * @param  \App\Filters\UserFilters  $filters
     * @return \App\Http\Resources\Collections\UserCollection
     */
    public function index(Meeting $meeting, UserFilters $filters)
    {
        $users = $meeting->users()->filter($filters)->resolve();

        return new UserCollection($users);
    }


$users = User::filter(new UserFilters(['search' => 'john']))->resolve();

sh
   php artisan vendor:publish --provider="tiagomichaelsousa\LaravelFilters\LaravelFiltersServiceProvider" --tag="config"