Skip to content

Commit

Permalink
Support Laravel 8
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Sep 6, 2020
1 parent c237bf0 commit db59747
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php: [7.4, 7.3, 7.2]
php: [7.4, 7.3]
database: [mysql, pgsql, sqlite, sqlsrv]
release: [stable, lowest]
include:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
}
],
"require": {
"php": "^7.2.5",
"illuminate/database": "^7.0"
"php": "^7.3",
"illuminate/database": "^8.0"
},
"require-dev": {
"laravel/homestead": "^10.0",
"phpunit/phpunit": "^8.5"
"laravel/homestead": "^11.0",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
36 changes: 36 additions & 0 deletions src/Casts/Uuid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Staudenmeir\EloquentJsonRelations\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class Uuid implements CastsAttributes
{
/**
* Cast the given value.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function get($model, $key, $value, $attributes)
{
return $value;
}

/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function set($model, $key, $value, $attributes)
{
return $value;
}
}
3 changes: 2 additions & 1 deletion src/Relations/Postgres/IsPostgresRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Expression;
use Staudenmeir\EloquentJsonRelations\Casts\Uuid;

trait IsPostgresRelation
{
Expand All @@ -25,7 +26,7 @@ protected function jsonColumn(Builder $query, Model $model, $column, $key)
$sql = '('.$sql.')::int';
}

if ($model->hasCast($key) && $model->getCasts()[$key] === 'uuid') {
if ($model->hasCast($key) && $model->getCasts()[$key] === Uuid::class) {
$sql = '('.$sql.')::uuid';
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Models;

use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentJsonRelations\Casts\Uuid;

class Category extends Model
{
Expand All @@ -13,7 +14,7 @@ class Category extends Model
protected $keyType = 'string';

protected $casts = [
'id' => 'uuid',
'id' => Uuid::class,
'options' => 'json'
];

Expand Down

0 comments on commit db59747

Please sign in to comment.