Skip to content

Conversation

@LarsGrevelink
Copy link
Contributor

Targets #36343 and laravel/ideas#2500. Now targets master due to the required change of the migrations as discussed in pull request #36363.

Adds JSON support for the Schema grammar when using them in virtual or stored columns. This makes the behaviour of referencing JSON columns the same as the Query grammar supports. Added support for both SQLite and MySQL since I was able to test these in real-life scenarios.

The current way of working with JSON data in columns requires to be e.g. MySQL specific;

Schema::table('my_table', function (Blueprint $table) {
    $table->string('my_extracted_value')->virtualAs('json_field->>"$.extract_me"');
});

This pull request applies the same grammar as the query grammar, already used within Laravel;

Schema::table('my_table', function (Blueprint $table) {
    $table->string('my_extracted_value')->virtualAs('json_field->extract_me');
});

If there are any questions related to the changes, please let me know.

- Move JSON related functions from query grammar to base grammar
- Add JSON wrap functions to schema grammar
- Add JSON support for MySQL and SQLite for virtualAs and storedAs columns
@taylorotwell taylorotwell merged commit 6f41768 into laravel:master Apr 1, 2021
@taylorotwell
Copy link
Member

Renamed methods to virtualAsJson and storedAsJson so that people can still drop-down to raw behavior if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants