1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 08:04:04 +00:00
Eloquent Virtual Column package.
Find a file
lukinovec 72de33a3d4
Add encrypted casts support + allow using the trait on multiple models (#14)
* Add encrypted casts test (wip)

* Handle and test 'encrypted' casts

* Add APP_KEY to phpunit.xml

* Update attribute casting in VirtualColumn

* Test casting of all default 'encrypted' castables

* Fix code style (php-cs-fixer)

* Handle custom castables in VirtualColumn

* Add custom encrypted castable

* Test custom encrypted castable, refactor test

* Move EncryptedCast class to VirtualColumnTest

* Correct expected/actual value order in assertions

* Break code style (testing)

* Fix code style (php-cs-fixer)

* Check Laravel CI version (testing)

* dd() Laravel version

* Delete dd()

* Delete get() and set() types

* Use non-lowercase custom cast class strings

* Check hasCast manually

* Correct encrypted castable logic

* Update src/VirtualColumn.php

* Use `$dataEncoded` bool instead of `$dataEncodingStatus` string

* Don't accept unused `$e`

* Refactor `encodeAttributes()`

* Use `$model->getCustomColumns()` instead of `static::getCustomColumns()`

* Use `$model` instead of `static` where possible

* Correct test

* Revert `static` -> `$model` changes

* Correct typo

* Refactor `$afterListeneres`

* Fix code style (php-cs-fixer)

* Make static things non-static in VirtualColumn

* Change method to non-static in test

* Add base class that uses VirtualColumn in tests

* Add encrypted castables docblock

* Fix merge

* Fix ParentModel change

* make $this and $model use clear and consistent

---------

Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
Co-authored-by: Samuel Štancl <samuel@archte.ch>
2023-11-08 10:08:34 +01:00
.github/workflows Add L10 support, remove L6 and L8 support (#11) 2023-02-16 11:34:42 +01:00
src Add encrypted casts support + allow using the trait on multiple models (#14) 2023-11-08 10:08:34 +01:00
tests Add encrypted casts support + allow using the trait on multiple models (#14) 2023-11-08 10:08:34 +01:00
.gitattributes Initial commit 2020-07-06 14:25:02 +02:00
.gitignore wip 2022-01-26 21:54:10 +05:00
.php-cs-fixer.php wip 2022-01-26 21:54:10 +05:00
check wip 2022-01-26 21:54:10 +05:00
composer.json Add L10 support, remove L6 and L8 support (#11) 2023-02-16 11:34:42 +01:00
LICENSE Initial commit 2020-07-06 14:25:02 +02:00
phpunit.xml Add encrypted casts support + allow using the trait on multiple models (#14) 2023-11-08 10:08:34 +01:00
phpunit.xml.bak Add encrypted casts support + allow using the trait on multiple models (#14) 2023-11-08 10:08:34 +01:00
README.md Add L10 support, remove L6 and L8 support (#11) 2023-02-16 11:34:42 +01:00

Eloquent Virtual Column

Installation

Supports Laravel 9 and 10.

composer require stancl/virtualcolumn

Usage

Use the VirtualColumn trait on your model:

use Illuminate\Database\Eloquent\Model;
use Stancl\VirtualColumn\VirtualColumn;

class MyModel extends Model
{
    use VirtualColumn;

    public $guarded = [];

    public static function getCustomColumns(): array
    {
        return [
            'id',
            'custom1',
            'custom2',
        ];
    }
}

Create a migration:

public function up()
{
    Schema::create('my_models', function (Blueprint $table) {
        $table->increments('id');

        $table->string('custom1')->nullable();
        $table->string('custom2')->nullable();

        $table->json('data');
    });
}

And store any data on your model:

$myModel = MyModel::create(['foo' => 'bar']);
$myModel->update(['foo' => 'baz']);