Filtan

Filtan is a powerful Laravel QueryFilter package designed to simplify and enhance the process of filtering Eloquent queries.

Downloads
2.2K
Stars
2

Bot releases are hidden (Show)

Filtan - Filtan v1.0.5 Latest Release

Published by patiencemanzen 8 months ago

โœจ Enhancements

  • Removed default strtolower method when passing query-string into custom query-function.

๐Ÿงผ Cleanup

  • Updated default output file contents for better clarity and structure.
  • Improved output message when php artisan make:filter command is executed.

๐Ÿ› Fixes

  • Fixed a simple typo in the php artisan make:filter command output message.
Filtan -

Published by patienceman-universe about 1 year ago

Filtan - Stable focus and target match

Published by patienceman-universe almost 2 years ago

stable relsease

Sometime you may want to pass the intended function in your query filter, ๐Ÿ†— to not pass through them all!
and well!, it might scale your application to run more faster!, because we have focus! right! ๐Ÿ‘ ๐Ÿฅณ

Right now, what you need to do is pass those function as parameter into your ->filter(QueryFilter, ['function-as-string']) function! ๐Ÿฅณ !, Let take quick example:

Let suppose we have Our QueryFilter class as:

  namespace App\Filters;
  
  use Patienceman\QueryFilter;
  
  class AirlineFilter extends QueryFilter {
      /**
       * search given string from airlines by name
       * @param string $query
       */
      public function query(string $query){
          $this->builder->where('name', 'LIKE', '%' . $query . '%');
      }
  
      /**
       * Get where code
       * @param string $code
       */
      public function code(string $code){
          $this->builder->where("code", "some example code");
      }

      /**
       * Get where location
       * @param string $location
       */
      public function location(string $location){
          $this->builder->where("location", "not attached");
      }
 }

So to work with that, you will: ๐Ÿ›‘ remember we want query and code ๐Ÿฅฝ :

  /**
   * Get all airlines that are open for ticket
   * 
   * @param AirlineFilter $filter
   * @return JsonResponse
   */
  public function index(AirlineFilter $filter) {
      $airlines = Airline::where('ticket', 'active)
                                   ->filter($filter, ['query', 'code'])
                                   ->get();

      return AirlineResource::collection($airlines);
  }

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Filtan - v1.0.2: Focus on specific function under your QueryFilter

Published by patienceman-universe almost 2 years ago

stable relsease

Sometime you may want to pass the intended function in your query filter, ๐Ÿ†— to not pass through them all!
and well!, it might scale your application to run more faster!, because we have focus! right! ๐Ÿ‘ ๐Ÿฅณ

Right now, what you need to do is pass those function as parameter into your ->filter(QueryFilter, ['function-as-string']) function! ๐Ÿฅณ !, Let take quick example:

Let suppose we have Our QueryFilter class as:

  namespace App\Filters;
  
  use Patienceman\QueryFilter;
  
  class AirlineFilter extends QueryFilter {
      /**
       * search given string from airlines by name
       * @param string $query
       */
      public function query(string $query){
          $this->builder->where('name', 'LIKE', '%' . $query . '%');
      }
  
      /**
       * Get where code
       * @param string $code
       */
      public function code(string $code){
          $this->builder->where("code", "some example code");
      }

      /**
       * Get where location
       * @param string $location
       */
      public function location(string $location){
          $this->builder->where("location", "not attached");
      }
 }

So to work with that, you will: ๐Ÿ›‘ remember we want query and code ๐Ÿฅฝ :

  /**
   * Get all airlines that are open for ticket
   * 
   * @param AirlineFilter $filter
   * @return JsonResponse
   */
  public function index(AirlineFilter $filter) {
      $airlines = Airline::where('ticket', 'active)
                                   ->filter($filter, ['query', 'code'])
                                   ->get();

      return AirlineResource::collection($airlines);
  }

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Filtan - 1.0.1 release

Published by patienceman-universe about 2 years ago

1.0.1- dev release

We all like automated stuff like

php artisan make:cake BananaCake 

that what I was doing for you so you don't have always to create files for filter traditional. ๐Ÿงจ

Just one command ๐ŸŽ‰
Let us use our current example of the AirPlane Model and create a new filter:

php artisan make:filter AirPlaneFilter

so it will create the filter file for u, Just in ```bash App\Services\Filters ``

  namespace App\Services\Filters;

  use Patienceman\Filtan\QueryFilter;

  class AirPlaneFilter extends QueryFilter {
      /**
       * public function query($query) {
       *     $this->builder->where('name', 'LIKE', '%' .  . '%')
       * }
       */
  }

๐Ÿ”ฅ ๐Ÿ”ฅ What best move we make: in the world?

So you may want even to specify the custom path for your filter, Just relax and add it in front of your filter name.
Let's take again our current example.

php artisan make:filter Model/AirPlaneFilter

๐Ÿ‘‹ ๐Ÿ‘‹ That is just what magic can make, awesome right?

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Filtan - Initial Release

Published by patienceman-universe about 2 years ago

Filtan from Patienceman

Flltan is fast and reusable laravel package for custom model query filters

Installation

To install the package don't require much requirement except to paste the following compand in laravel terminal, and the you're good to go.

composer require patienceman/filtan

Usage

In your App/Services directory, create new folrder called Filters, where you gonna put all of your model filter files.

After everything, you can add your custom model filter file, let take example of App/Services/Filters/AirplaneFilters class.

    namespace App\Services\Filters;
    
    use Patienceman\Filtan\QueryFilter;

    class AirplaneFilter extends QueryFilter {

        public function query(string $query){
            $this->builder->where('name', 'LIKE', '%' . $query . '%');
        }

    }

So now you have your filters function to be applied when new AirplaneModel query called!,

We need to communicate to model and tell that we have it filters, so that we can call it anytime!!,
So let use filterable trait to enable filter builder.

    namespace App\Models;

    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Database\Eloquent\Model;
    use Patienceman\Filtan\Filterable;

    class Airplane extends Model {
        use HasFactory, Filterable;
    }

Boom Boom, from now on, we are able call our fiter anytime, any place that need Airplane model, so let see how we can use this in our controller

    namespace App\Http\Controllers\ApiControllers;

    use App\Http\Controllers\Controller;
    use App\Models\User;
    use App\Services\Filters\CompanyFilter;
    use Illuminate\Http\JsonResponse;
    use Illuminate\Http\Request;

    class AirplaneController extends Controller {
        /**
         * Display a listing of the resource.
         *
         * @return JsonResponse
         */
        public function index(CompanyFilter $filter): JsonResponse {
            $planes = Airplane::allPlanes()->filter($filter)->get();

            return successResponse(
                AirplaneResource::collection($planes),
                AirplaneAlert::DISPLAY_MESSAGE
            );
        }
    }

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT