Laravel 9 Update (#1413)

Update to Laravel 9 and PHP 8+

Co-authored-by: B.Fatih KOZ <fatih.koz@gmail.com>
This commit is contained in:
Nabeel S
2022-03-14 11:45:18 -04:00
committed by GitHub
parent 00bf18c225
commit 12848091a2
340 changed files with 6130 additions and 4502 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Models\Casts;
use App\Support\Units\Distance;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
class DistanceCast implements CastsAttributes
{
/**
* Transform the attribute from the underlying model values.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
*
* @return mixed
*/
public function get($model, string $key, $value, array $attributes)
{
if ($value instanceof Distance) {
return $value;
}
try {
return new Distance($value, config('phpvms.internal_units.distance'));
} catch (NonNumericValue $e) {
} catch (NonStringUnitName $e) {
return $value;
}
return $value;
}
/**
* Transform the attribute to its underlying model values.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
*
* @return mixed
*/
public function set($model, string $key, $value, array $attributes)
{
if ($value instanceof Distance) {
return $value->toUnit(config('phpvms.internal_units.distance'));
}
return $value;
}
}