PHPackages                             pascalvgemert/laravel-lookupable - 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. pascalvgemert/laravel-lookupable

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

pascalvgemert/laravel-lookupable
================================

Lookupable Trait for Laravel eloquent models for quick and efficient table lookups.

0.1.3(6y ago)05MITPHPPHP &gt;=7.0

Since Aug 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/pascalvgemert/laravel-lookupable)[ Packagist](https://packagist.org/packages/pascalvgemert/laravel-lookupable)[ Docs](https://github.com/pascalvgemert/laravel-lookupable)[ RSS](/packages/pascalvgemert-laravel-lookupable/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Laravel Lookupable
==================

[](#laravel-lookupable)

Lookupable Trait for Laravel eloquent models for quick and efficient table lookups.

[![Total Downloads](https://camo.githubusercontent.com/cd098a341adafa5a9e66f875c054645bf9895533d2dbbfbfd1069fcb4518a524/68747470733a2f2f706f7365722e707567782e6f72672f70617363616c7667656d6572742f6c61726176656c2d6c6f6f6b757061626c652f646f776e6c6f616473)](https://packagist.org/packages/pascalvgemert/laravel-lookupable)[![License](https://camo.githubusercontent.com/35ca2133be9168beff19ccb9f5dcdcc2049156098faf09cfb4a6cf30706e3bce/68747470733a2f2f706f7365722e707567782e6f72672f70617363616c7667656d6572742f6c61726176656c2d6c6f6f6b757061626c652f6c6963656e7365)](https://packagist.org/packages/pascalvgemert/laravel-lookupable)

### Requires Laravel 5.5 or higher!

[](#requires-laravel-55-or-higher)

About the package
-----------------

[](#about-the-package)

When building more complex applications, lookup queries can add up without you even knowing. The lookupable trait will only get the lookup instances once per request and store them in memory. Every next time you want to lookup a lookupable instance of the same Model, the lookup methods will access the in memory stored instances and prevent a query.

**Example:**You have a lookup table for statuses like `pending`, `draft`, `published`, `deleted`. You can access these instances multiple times, with only one query per request:

```
$draftStatus = Status::lookup('draft'); // Executes the select * query and puts all instances in memory
$publishedStatus = Status::lookup('published'); // Will get the instance from memory
$deletedStatus = Status::lookup('deleted'); // Will get the instance from memory
```

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

[](#installation)

You can install the package via composer:

```
composer require pascalvgemert/laravel-lookup
```

Usage
-----

[](#usage)

The `Lookupable` trait can be used only for Eloquent Models

```
class Role extends \Illuminate\Database\Eloquent\Model
{
    use Lookupable/Lookupable;
}
```

### Example table scheme for 'Roles'

[](#example-table-scheme-for-roles)

ididentifiertitle1adminAdmin User2userSystem User3guestGuest User### Lookupable methods

[](#lookupable-methods)

After this you can lookup instances easily with the following methods:

#### Single Lookup

[](#single-lookup)

```
/** @var \App\Models\Role|null **/
$role = Role::lookup('admin');

```

#### Single Lookup which throws an \\Illuminate\\Database\\Eloquent\\ModelNotFoundException error when no record could be found

[](#single-lookup-which-throws-an-illuminatedatabaseeloquentmodelnotfoundexception-error-when-no-record-could-be-found)

```
/** @var \App\Models\Role **/
$role = Role::lookupOrFail('admin');

```

#### Multiple Lookup

[](#multiple-lookup)

```
/** @var \Illuminate\Database\Eloquent\Collection **/
$roles = Role::lookupMany(['admin', 'guest']);

```

#### Multiple Lookup which throws an \\Illuminate\\Database\\Eloquent\\ModelNotFoundException error when any of the given record could NOT be found

[](#multiple-lookup-which-throws-an-illuminatedatabaseeloquentmodelnotfoundexception-error-when-any-of-the-given-record-could-not-be-found)

```
/** @var \Illuminate\Database\Eloquent\Collection **/
$roles = Role::lookupManyOrFail(['admin', 'guest']);

```

### Soft Deleted items

[](#soft-deleted-items)

All of the above methods can except a second parameter (`bool $withTrashed = false;`), to also return with Soft Deleted items.

> Note: When trying to use the Soft Deleted items, please make sure your Eloquent Model implements the \\Illuminate\\Database\\Eloquent\\SoftDeletes trait.

### I don't have an `identifier` column?

[](#i-dont-have-an-identifier-column)

So your database table doesn't contain an `identifier` column and looks like this `Country` table for example:

idcodetitle1NLNetherlands2UKGreat Brittain3BEBelgium4USUnited States5......No worries, you can define your own lookup column name in your model like so:

```
class Country extends \Illuminate\Database\Eloquent\Model
{
    use Lookupable/Lookupable;

    protected $lookupColumn = 'code';
}
```

Credits
-------

[](#credits)

- [Pascal van Gemert](https://github.com/pascalvgemert)
- [Kevin op den Kamp](https://github.com/papa-smurf) (for inspiration)
- [Startselect](https://startselect.com)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

3

Last Release

2508d ago

PHP version history (2 changes)0.1.0PHP &gt;=7.1.0

0.1.3PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/609e8d7caaa1dacc8b03bcc8347b5732e5a91399bb843e5b44fec66be256f35a?d=identicon)[pascalvgemert](/maintainers/pascalvgemert)

---

Top Contributors

[![pascalvgemert](https://avatars.githubusercontent.com/u/1567379?v=4)](https://github.com/pascalvgemert "pascalvgemert (15 commits)")

---

Tags

lookup tableslookuppascalvgemertlaravel-lookupable

### Embed Badge

![Health badge](/badges/pascalvgemert-laravel-lookupable/health.svg)

```
[![Health](https://phpackages.com/badges/pascalvgemert-laravel-lookupable/health.svg)](https://phpackages.com/packages/pascalvgemert-laravel-lookupable)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M611](/packages/spatie-laravel-medialibrary)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M91](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M42](/packages/kirschbaum-development-eloquent-power-joins)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M23](/packages/yajra-laravel-oci8)[awobaz/compoships

Laravel relationships with support for composite/multiple keys

1.2k11.7M46](/packages/awobaz-compoships)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.3M19](/packages/bavix-laravel-wallet)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
