{"id":21696642,"url":"https://github.com/patrickcurl/laravel-computed-columns","last_synced_at":"2026-04-12T19:39:40.627Z","repository":{"id":60557606,"uuid":"543933971","full_name":"patrickcurl/laravel-computed-columns","owner":"patrickcurl","description":"Updated Builder/Schema for easier migrations. ","archived":false,"fork":false,"pushed_at":"2023-10-09T12:58:21.000Z","size":110,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-25T14:12:02.048Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickcurl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-01T07:30:10.000Z","updated_at":"2022-10-01T07:30:15.000Z","dependencies_parsed_at":"2024-11-25T22:46:51.127Z","dependency_job_id":null,"html_url":"https://github.com/patrickcurl/laravel-computed-columns","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickcurl%2Flaravel-computed-columns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickcurl%2Flaravel-computed-columns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickcurl%2Flaravel-computed-columns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickcurl%2Flaravel-computed-columns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickcurl","download_url":"https://codeload.github.com/patrickcurl/laravel-computed-columns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244636401,"owners_count":20485442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T19:21:01.007Z","updated_at":"2025-12-31T00:05:21.732Z","avatar_url":"https://github.com/patrickcurl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adds the methods: md5AsComputed, jsonFieldStoredAs, manyJsonFieldsStoredAs, concatWsStoredAs\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/patrickcurl/laravel-computed-columns.svg?style=flat-square)](https://packagist.org/packages/patrickcurl/laravel-computed-columns)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/patrickcurl/laravel-computed-columns/run-tests?label=tests)](https://github.com/patrickcurl/laravel-computed-columns/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/patrickcurl/laravel-computed-columns/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/patrickcurl/laravel-computed-columns/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/patrickcurl/laravel-computed-columns.svg?style=flat-square)](https://packagist.org/packages/patrickcurl/laravel-computed-columns)\n\nThis package is an extension to laravel migrations to add some more optimized virtual/storedAs fields based on common use cases (at least my own);\n\n## Support us\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require patrickcurl/laravel-computed-columns\n```\n\nYou can publish and run the migrations with:\n\n## Usage\n\nI'm planning on better documentation but the simplest way to jump in is look at some code.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nreturn new class() extends Migration {\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('locations');\n        Schema::dropIfExists('locateables');\n    }\n\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('locations', function (Blueprint $table) {\n            $table-\u003eid();\n            $table-\u003ejson('data')-\u003enullable();\n\n            $table-\u003ecomputedJsonColumns( // notice the plurality of columns.\n                'stored' // the type, accepts: 'stored' and 'virtual'\n                'data', // the json column to extract data from.\n                [ // The fields in the data json object to convert to computed fields.\n                    'type',\n                    'country',\n                    'country_code',\n                    'state',\n                    'postcode',\n                    'city',\n                    'lat',\n                    'lng',\n                ], // loop over these fields and run the storedAs method see example below.\n                true // should each field be nullable?\n            );\n\n            // This is the equivalent of running:\n            // $field = 'data-\u003e';\n            // $path = 'country';\n            // $this-\u003estring('type')-\u003estoredAs('json_unquote(json_extract('.$field.$path.'))');\n\n\n            // concatWsStoredAs($column, $default, $separator, ...$fields)\n            $table-\u003ecomputedConcatWsColumn(\n                'stored' // type\n                'label', // computed column name\n                'data-\u003elabel', // json path default value if other sources come up null.\n                ', ', // separator\n                'city', // ...$fields|$fields[] which fields on data to convert from:\n                'state', // e.g. state will give you $model-\u003estate === $model-\u003edata-\u003estate;\n                'country',\n                'postcode'\n            ); // This will use the default if it exists, otherwise it'll create a default either from json nested keys where fields are ['data-\u003ecity', 'data-\u003estate', etc....];\n\n            // This one simply creates an id, my location example basically does a lookup of data via openstreetmaps, and caches the label, and then if someone adds that to their profile as their location it'll pull it all in at that point either from the api, or the cache, or an existing location as we're only dealing with city/state not actual full addresses.\n\n            // This isn't the most secure thing, for an id that's not critical that it's secret this is fine, but I wouldn't use it to hash passwords!\n            $table-\u003ecomputedMd5Column(\n                'stored', // type\n                'uid', // column\n                'label' // label column will be used, could also use data-\u003elabel to use the original json to map from.\n            );\n\n            // alternately I could've used :\n            $table-\u003ecomputedWrappedColumn(\n                'stored',\n                'MD5',\n                'uid',\n                'label'\n            ) ;\n\n            $table-\u003etimestamps();\n        });\n\n        Schema::create('locateables', function (Blueprint $table) {\n            $table-\u003eid();\n            $table-\u003eforeignId('location_id')-\u003econstrained();\n            $table-\u003emorphs('locateable');\n            $table-\u003eunique(['location_id', 'locateable_id', 'locateable_type']);\n        });\n    }\n};\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Patrick Curl](https://github.com/patrickcurl)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickcurl%2Flaravel-computed-columns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickcurl%2Flaravel-computed-columns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickcurl%2Flaravel-computed-columns/lists"}