Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 78e24ab

Browse files
Merge branch 'patch-1'
2 parents ef1b302 + e051068 commit 78e24ab

File tree

4 files changed

+55
-9
lines changed

4 files changed

+55
-9
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ cache:
77
matrix:
88
include:
99
- php: 7.2
10-
env: ILLUMINATE_VERSION=6.0.*
10+
env: ILLUMINATE_VERSION=7.*
1111
- php: 7.3
12-
env: ILLUMINATE_VERSION=6.0.*
12+
env: ILLUMINATE_VERSION=7.*
13+
- php: 7.3
14+
env: ILLUMINATE_VERSION=7.*
1315

1416
before_install: travis_retry composer require "illuminate/database:${ILLUMINATE_VERSION}" "illuminate/events:${ILLUMINATE_VERSION}" --no-update -v
1517

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Laravel Efficient UUIDs
2-
## v3.1.0
2+
## v4.0.0
33

44
[![Build Status](https://travis-ci.org/michaeldyrynda/laravel-efficient-uuid.svg?branch=master)](https://travis-ci.org/michaeldyrynda/laravel-efficient-uuid)
55
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-efficient-uuid/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-efficient-uuid/?branch=master)
@@ -15,6 +15,8 @@ This package extends the default grammar file for the given MySQL connection add
1515

1616
As of 3.0, this package _no longer overrides_ Laravel's default `uuid` method, but rather adds a separate `efficientUuid` field, due to compatibility issues with Laravel Telescope (#11).
1717

18+
As of 4.0, this package uses a [custom cast](https://laravel.com/docs/7.x/eloquent-mutators#custom-casts) to provide casting functionality into your models.
19+
1820
> **Note**: This package purposely does not use [package discovery](https://laravel.com/docs/5.8/packages#package-discovery), as it makes changes to the MySQL schema file, which is something you should explicitly enable.
1921
2022
MySQL and SQLite are the only supported connection types, although I welcome any pull requests to implement this functionality for other database drivers.
@@ -59,14 +61,17 @@ You will need to add a cast to your model when using [laravel-model-uuid](https:
5961

6062
namespace App;
6163

62-
use Illuminate\Database\Eloquent\Model;
64+
use Dyrynda\Database\Support\Casts\EfficientUuid;
6365
use Dyrynda\Database\Support\GeneratesUuid;
66+
use Illuminate\Database\Eloquent\Model;
6467

6568
class Post extends Model
6669
{
6770
use GeneratesUuid;
6871

69-
protected $casts = ['uuid' => 'uuid'];
72+
protected $casts = [
73+
'uuid' => EfficientUuid::class,
74+
];
7075
}
7176
```
7277

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.2",
15-
"illuminate/container": "^6.0",
16-
"illuminate/database": "^6.0"
14+
"php": "^7.2.5",
15+
"illuminate/container": "^7.0",
16+
"illuminate/contracts": "^7.0",
17+
"illuminate/database": "^7.0"
1718
},
1819
"require-dev": {
1920
"phpunit/phpunit": "^8.0",
2021
"mockery/mockery": "^1.2.3",
21-
"orchestra/testbench": "^4.0"
22+
"orchestra/testbench": "^5.0"
2223
},
2324
"autoload": {
2425
"psr-4": {

src/Casts/EfficientUuid.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Support\Casts;
4+
5+
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6+
7+
class EfficientUuid implements CastsAttributes
8+
{
9+
/**
10+
* Transform the attribute from the underlying model values.
11+
*
12+
* @param \Illuminate\Database\Eloquent\Model $model
13+
* @param string $key
14+
* @param mixed $value
15+
* @param array $attributes
16+
* @return mixed
17+
*/
18+
public function get($model, string $key, $value, array $attributes)
19+
{
20+
return $model->resolveUuid()->fromBytes($value)->toString();
21+
}
22+
23+
/**
24+
* Transform the attribute to its underlying model values.
25+
*
26+
* @param \Illuminate\Database\Eloquent\Model $model
27+
* @param string $key
28+
* @param mixed $value
29+
* @param array $attributes
30+
* @return array
31+
*/
32+
public function set($model, string $key, $value, array $attributes)
33+
{
34+
return [
35+
$key => $model->resolveUuid()->fromString(strtolower($value))->getBytes(),
36+
];
37+
}
38+
}

0 commit comments

Comments
 (0)