PHPackages                             berthott/laravel-targetable - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. berthott/laravel-targetable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

berthott/laravel-targetable
===========================

Laravel Helper for targeting classes by their traits

3.0.3(2y ago)0890↓50%6MITPHP

Since Nov 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/berthott/laravel-targetable)[ Packagist](https://packagist.org/packages/berthott/laravel-targetable)[ RSS](/packages/berthott-laravel-targetable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (6)

[![test workflow](https://github.com/berthott/laravel-targetable/actions/workflows/test.yml/badge.svg)](https://github.com/berthott/laravel-targetable/actions/workflows/test.yml/badge.svg)

Laravel-Targetable
==================

[](#laravel-targetable)

Laravel Helper for targeting classes by their traits.

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

[](#installation)

```
$ composer require berthott/laravel-targetable

```

Usage
-----

[](#usage)

- Create your own service inheriting `berthott\Targetable\Services\TargetableService`
- Pass the trait you want to target, and the config name you chose

```
class TestService extends TargetableService
{
    public function __construct()
    {
        parent::__construct(YourTrait::class, 'your-config');
    }
}
```

- For further details on possibilities on how to utilize this service have a look inside `tests/BasicTargetable`
- You might use an interface instead of a trait by using `Mode::Contract` as a 3rd argument on TargetableService

Options
-------

[](#options)

To change the default options add the following options to your librarys config file:

- `namespace`: String or array with one ore multiple namespaces that should be monitored for the configured trait. Defaults to `App\Models`.
- `namespace_mode`: Defines the search mode for the namespaces. `ClassFinder::STANDARD_MODE` will only find the exact matching namespace, `ClassFinder::RECURSIVE_MODE` will find all subnamespaces. Defaults to `ClassFinder::STANDARD_MODE`.
- `prefix`: Defines the route prefix. Defaults to `api`.

Your config might look like this:

```
