Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Eloquent\Casts;
4
 
5
use Illuminate\Contracts\Database\Eloquent\Castable;
6
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\Facades\Crypt;
9
 
10
class AsEncryptedCollection implements Castable
11
{
12
    /**
13
     * Get the caster class to use when casting from / to this cast target.
14
     *
15
     * @param  array  $arguments
16
     * @return object|string
17
     */
18
    public static function castUsing(array $arguments)
19
    {
20
        return new class implements CastsAttributes
21
        {
22
            public function get($model, $key, $value, $attributes)
23
            {
24
                if (isset($attributes[$key])) {
25
                    return new Collection(json_decode(Crypt::decryptString($attributes[$key]), true));
26
                }
27
 
28
                return null;
29
            }
30
 
31
            public function set($model, $key, $value, $attributes)
32
            {
33
                if (! is_null($value)) {
34
                    return [$key => Crypt::encryptString(json_encode($value))];
35
                }
36
 
37
                return null;
38
            }
39
        };
40
    }
41
}