{"id":37265117,"url":"https://github.com/imliam/yii2-traits","last_synced_at":"2026-01-16T00:05:04.123Z","repository":{"id":56990487,"uuid":"141913868","full_name":"imliam/yii2-traits","owner":"imliam","description":"A collection of miscellaneous traits to extend parts of Yii2.","archived":false,"fork":false,"pushed_at":"2018-07-22T17:01:05.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T12:25:41.407Z","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/imliam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-22T16:49:10.000Z","updated_at":"2018-07-22T16:59:00.000Z","dependencies_parsed_at":"2022-08-21T13:50:24.731Z","dependency_job_id":null,"html_url":"https://github.com/imliam/yii2-traits","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/imliam/yii2-traits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fyii2-traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fyii2-traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fyii2-traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fyii2-traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imliam","download_url":"https://codeload.github.com/imliam/yii2-traits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imliam%2Fyii2-traits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-16T00:05:03.263Z","updated_at":"2026-01-16T00:05:04.118Z","avatar_url":"https://github.com/imliam.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 Traits\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/imliam/yii2-traits.svg)](https://packagist.org/packages/imliam/yii2-traits)\n[![Total Downloads](https://img.shields.io/packagist/dt/imliam/yii2-traits.svg)](https://packagist.org/packages/imliam/yii2-traits)\n[![License](https://img.shields.io/github/license/imliam/yii2-traits.svg)](LICENSE.md)\n\nA collection of miscellaneous traits to extend parts of Yii2.\n\n\u003c!-- TOC --\u003e\n\n- [Yii2 Traits](#yii2-traits)\n    - [💾 Installation](#💾-installation)\n    - [📝 Usage](#📝-usage)\n        - [`yii\\db\\Migration`](#yii\\db\\migration)\n            - [Migration@fillColumn(string $table, string $column, $value)](#migrationfillcolumnstring-table-string-column-value)\n        - [`yii\\db\\ActiveRecord`](#yii\\db\\activerecord)\n            - [ActiveRecord@firstOrCreate(array $attributes, array $values = []): self](#activerecordfirstorcreatearray-attributes-array-values---self)\n            - [ActiveRecord@create(array $attributes): self](#activerecordcreatearray-attributes-self)\n            - [ActiveRecord@make(array $attributes): self](#activerecordmakearray-attributes-self)\n            - [ActiveRecord@deleteIfExists(array $attributes)](#activerecorddeleteifexistsarray-attributes)\n            - [ActiveRecord@first(string $orderBy = null)](#activerecordfirststring-orderby--null)\n    - [✅ Testing](#✅-testing)\n    - [🔖 Changelog](#🔖-changelog)\n    - [⬆️ Upgrading](#⬆️-upgrading)\n    - [🎉 Contributing](#🎉-contributing)\n        - [🔒 Security](#🔒-security)\n    - [👷 Credits](#👷-credits)\n    - [♻️ License](#♻️-license)\n\n\u003c!-- /TOC --\u003e\n\n## 💾 Installation\n\nYou can install the package with [Composer](https://getcomposer.org/) using the following command:\n\n```bash\ncomposer require imliam/yii2-traits:^1.0.0\n```\n\nOnce installed, you can then `use` the traits in your existing classes.\n\n## 📝 Usage\n\n### `yii\\db\\Migration`\n\n#### Migration@fillColumn(string $table, string $column, $value)\n\nSet the default value of an existing column.\n\n```php\n\u003c?php\n\nuse yii\\db\\Migration;\nuse ImLiam\\Yii2Traits\\MigrationHelpers;\n\nclass m180524_091606_run_migration extends Migration\n{\n    use MigrationHelpers;\n\n    public function safeUp()\n        $this-\u003eaddColumn('users', 'country', 'string');\n        $this-\u003efillColumn('users', 'country', 'GB');\n    }\n}\n```\n\n### `yii\\db\\ActiveRecord`\n\n#### ActiveRecord@firstOrCreate(array $attributes, array $values = []): self\n\nGet the first record matching the attributes or create it. Perfect for handling pivot models.\n\n```php\n\u003c?php\n\nuse yii\\db\\ActiveRecord;\nuse ImLiam\\Yii2Traits\\ActiveRecordHelpers;\n\nclass User extends ActiveRecord\n{\n    use ActiveRecordHelpers;\n}\n\n$user = User::firstOrCreate(['id' =\u003e 1], ['username' =\u003e 'Admin']);\n// Returns user ID 1 if it exists in the database, or creates\n// a new user with the ID of 1 and username of 'Admin'\n```\n\n#### ActiveRecord@create(array $attributes): self\n\nCreate a new instance of the model and persist it.\n\n```php\n\u003c?php\n\nuse yii\\db\\ActiveRecord;\nuse ImLiam\\Yii2Traits\\ActiveRecordHelpers;\n\nclass User extends ActiveRecord\n{\n    use ActiveRecordHelpers;\n}\n\n$user = User::create(['username' =\u003e 'Admin']);\n// Creates and returns a new user with the username of 'Admin'\n```\n\n#### ActiveRecord@make(array $attributes): self\n\nCreate a new instance of the model without persisting it.\n\n```php\n\u003c?php\n\nuse yii\\db\\ActiveRecord;\nuse ImLiam\\Yii2Traits\\ActiveRecordHelpers;\n\nclass User extends ActiveRecord\n{\n    use ActiveRecordHelpers;\n}\n\n$user = User::make(['username' =\u003e 'Admin']);\n// Makes a new user with the username of 'Admin' but does NOT save it to the database\n```\n\n#### ActiveRecord@deleteIfExists(array $attributes)\n\nDelete a model matching the given attributes.\n\n```php\n\u003c?php\n\nuse yii\\db\\ActiveRecord;\nuse ImLiam\\Yii2Traits\\ActiveRecordHelpers;\n\nclass User extends ActiveRecord\n{\n    use ActiveRecordHelpers;\n}\n\nUser::deleteIfExists(['username' =\u003e 'Admin']);\n// Deletes all users with the username of 'Admin'\n```\n\n#### ActiveRecord@first(string $orderBy = null)\n\nGet the first instance of a model.\n\n```php\n\u003c?php\n\nuse yii\\db\\ActiveRecord;\nuse ImLiam\\Yii2Traits\\ActiveRecordHelpers;\n\nclass User extends ActiveRecord\n{\n    use ActiveRecordHelpers;\n}\n\n$user = User::first();\n// Returns the first user in the database\n```\n\n## ✅ Testing\n\n``` bash\ncomposer test\n```\n\n## 🔖 Changelog\n\nPlease see [the changelog file](CHANGELOG.md) for more information on what has changed recently.\n\n## ⬆️ Upgrading\n\nPlease see the [upgrading file](UPGRADING.md) for details on upgrading from previous versions.\n\n## 🎉 Contributing\n\nPlease see the [contributing file](CONTRIBUTING.md) and [code of conduct](CODE_OF_CONDUCT.md) for details on contributing to the project.\n\n### 🔒 Security\n\nIf you discover any security related issues, please email liam@liamhammett.com instead of using the issue tracker.\n\n## 👷 Credits\n\n- [Liam Hammett](https://github.com/imliam)\n- [All Contributors](../../contributors)\n\n## ♻️ License\n\nThe MIT License (MIT). Please see the [license file](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimliam%2Fyii2-traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimliam%2Fyii2-traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimliam%2Fyii2-traits/lists"}