Initial Commit
This commit is contained in:
commit
ddf09fe00c
113 changed files with 187148 additions and 0 deletions
45
app/Models/Casts/GameSettingsCaster.php
Normal file
45
app/Models/Casts/GameSettingsCaster.php
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in a new issue