Skip to content

Commit

Permalink
Create 2.eloquent-ulidable.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kduma authored Jul 26, 2023
1 parent fdd733d commit b9d4bef
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions content/3.libraries/2.eloquent-ulidable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Eloquent ULID-able
type: library
platform: Laravel
github: https://github.com/kduma-OSS/L5-eloquent-ulidable
---

# Eloquent ULID-able

Eases using and generating ulid's in Laravel Eloquent models.

## Setup
Install it using composer

```bash
composer require kduma/eloquent-ulidable
```

## Prepare models
Inside your model (not on top of file) add following lines:

```php
use \KDuma\Eloquent\Ulidable;
```

In database create `ulid` string field. If you use migrations, you can use following snippet:

```php
$table->ulid()->unique();
```

## Usage
By default it generates slug on first save.

- `$model->regenerateUlid()`{lang="php"} - Generate new uuid. (Remember to save it by yourself)
- `Model::whereUlid($ulid)->first()`{lang="php"} - Find by ulid. (`whereUlid` is query scope)

0 comments on commit b9d4bef

Please sign in to comment.