Archived
1
0
Fork 0

Initial Commit

This commit is contained in:
Henrik Hautakoski 2021-10-18 11:53:33 +02:00
commit ddf09fe00c
113 changed files with 187148 additions and 0 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace App\Models\Casts;
use App\Game\GameSettings;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use InvalidArgumentException;
class GameSettingsCaster implements CastsAttributes
{
/**
* Cast the given value.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return GameSettings
*/
public function get($model, $key, $value, $attributes)
{
$value = json_decode($value, true);
return new GameSettings($value);
}
/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param GameSettings|array $value
* @param array $attributes
* @return string
*/
public function set($model, $key, $value, $attributes)
{
if (is_array($value)) {
$value = new GameSettings($value);
} else if (!($value instanceof GameSettings)) {
throw new InvalidArgumentException('The given value must be an GameSettings instance or array.');
}
return json_encode($value->toArray());
}
}