Skip to content

Commit 575a63d

Browse files
committed
2 parents 8e3c5e0 + 327d67d commit 575a63d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# Laravel Lookupable
22
Lookupable Trait for Laravel eloquent models for quick and efficient table lookups.
33

4+
[![Total Downloads](https://poser.pugx.org/pascalvgemert/laravel-lookupable/downloads)](https://packagist.org/packages/pascalvgemert/laravel-lookupable)
5+
[![License](https://poser.pugx.org/pascalvgemert/laravel-lookupable/license)](https://packagist.org/packages/pascalvgemert/laravel-lookupable)
6+
7+
## About the package
8+
9+
When building more complex applications, lookup queries can add up without you even knowing.
10+
The lookupable trait will only get the lookup instances once per request and store them in memory.
11+
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.
12+
13+
**Example:**
14+
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:
15+
16+
```php
17+
$draftStatus = Status::lookup('draft'); // Executes the select * query and puts all instances in memory
18+
$publishedStatus = Status::lookup('published'); // Will get the instance from memory
19+
$deletedStatus = Status::lookup('deleted'); // Will get the instance from memory
20+
```
21+
422
## Installation
523

624
You can install the package via composer:

0 commit comments

Comments
 (0)