PHPackages                             h-farm/laravel-excludable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. h-farm/laravel-excludable

ActiveLibrary[Database &amp; ORM](/categories/database)

h-farm/laravel-excludable
=========================

Laravel Excludable

4.1.0(2y ago)622596[4 PRs](https://github.com/maize-tech/laravel-excludable/pulls)MITPHPPHP ^8.0CI passing

Since May 5Pushed 3mo ago7 watchersCompare

[ Source](https://github.com/maize-tech/laravel-excludable)[ Packagist](https://packagist.org/packages/h-farm/laravel-excludable)[ Docs](https://github.com/maize-tech/laravel-excludable)[ GitHub Sponsors](https://github.com/maize-tech)[ RSS](/packages/h-farm-laravel-excludable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (11)Used By (0)

   ![Social Card of Laravel Excludable](/art/socialcard-light.png)

Laravel Excludable
==================

[](#laravel-excludable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1bde27a0b57d41db815ad2e57841115f2638a413676ce95b9eb140e056cd7059/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61697a652d746563682f6c61726176656c2d6578636c756461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-excludable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/00702420611fef13c677d7eefa7c5b0bb8d363d28485969cc0a61aa0ded0c551/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d6578636c756461626c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-excludable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/1f1964c2971b2b44cada93ce50f00f494b3bec6843d58698be24980113a223be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61697a652d746563682f6c61726176656c2d6578636c756461626c652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/maize-tech/laravel-excludable/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/e475c98a842529d38d70a567d6686c8595ca6780833b490c034d10109be54b08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61697a652d746563682f6c61726176656c2d6578636c756461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/maize-tech/laravel-excludable)

Easily exclude model entities from eloquent queries.

This package allows you to define a subset of model entities that should be excluded from eloquent queries. You will be able to override the default `Exclusion` model and its associated migration, so you can eventually restrict the exclusion context by defining the entity that should effectively exclude the subset.

An example usage could be an application with a multi tenant scenario and a set of global entities. While those entities should be accessible by all tenants, some of them might want to hide a subset of those entities for their users. You can find an example in the [Usage](#usage) section.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require maize-tech/laravel-excludable
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Maize\Excludable\ExcludableServiceProvider" --tag="excludable-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Maize\Excludable\ExcludableServiceProvider" --tag="excludable-config"
```

This is the content of the published config file:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Exclusion model
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the exclusion model.
    |
    */

    'exclusion_model' => Maize\Excludable\Models\Exclusion::class,

    /*
    |--------------------------------------------------------------------------
    | Has exclusion query
    |--------------------------------------------------------------------------
    |
    | Here you may specify the fully qualified class name of the exclusion query.
    |
    */

    'has_exclusion_query' => Maize\Excludable\Queries\HasExclusionQuery::class,
];
```

Usage
-----

[](#usage)

### Basic

[](#basic)

To use the package, add the `Maize\Excludable\Excludable` trait to all models you want to make excludable.

Here's an example model including the `Excludable` trait:

```
