{"id":37001766,"url":"https://github.com/liudding/uniquewith-validator","last_synced_at":"2026-01-14T00:23:53.205Z","repository":{"id":56974236,"uuid":"131135922","full_name":"liudding/uniquewith-validator","owner":"liudding","description":"Custom Laravel Validator for combined unique indexes","archived":false,"fork":true,"pushed_at":"2018-04-26T10:08:08.000Z","size":84,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-11-23T09:26:10.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"felixkiss/uniquewith-validator","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liudding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-26T09:55:52.000Z","updated_at":"2021-01-11T11:41:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/liudding/uniquewith-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/liudding/uniquewith-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Funiquewith-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Funiquewith-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Funiquewith-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Funiquewith-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liudding","download_url":"https://codeload.github.com/liudding/uniquewith-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liudding%2Funiquewith-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406482,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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-14T00:23:52.522Z","updated_at":"2026-01-14T00:23:53.197Z","avatar_url":"https://github.com/liudding.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unique_with Validator Rule For Laravel\n\n[![Build Status](https://travis-ci.org/felixkiss/uniquewith-validator.svg?branch=master)](https://travis-ci.org/felixkiss/uniquewith-validator)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/felixkiss/uniquewith-validator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/felixkiss/uniquewith-validator/?branch=master)\n\nThis package contains a variant of the `validateUnique` rule for Laravel, that allows for validation of multi-column UNIQUE indexes.\n\n## Documentation for older versions\n\n - [Laravel 4](https://github.com/felixkiss/uniquewith-validator/blob/2.0.8/README.md#laravel-4)\n\n## Installation\n\nInstall the package through [Composer](http://getcomposer.org).\nOn the command line:\n\n```\ncomposer require felixkiss/uniquewith-validator\n```\n\n## Configuration\n\nAdd the following to your `providers` array in `config/app.php`:\n\n```php\n'providers' =\u003e [\n    // ...\n\n    Felixkiss\\UniqueWithValidator\\ServiceProvider::class,\n],\n```\n\n## Usage\n\nUse it like any `Validator` rule:\n\n```php\n$rules = [\n    '\u003cfield1\u003e' =\u003e 'unique_with:\u003ctable\u003e,\u003cfield2\u003e[,\u003cfield3\u003e,...,\u003cignore_rowid\u003e]',\n];\n```\n\nSee the [Validation documentation](http://laravel.com/docs/validation) of Laravel.\n\n### Specify different column names in the database\n\nIf your input field names are different from the corresponding database columns,\nyou can specify the column names explicitly.\n\ne.g. your input contains a field 'last_name', but the column in your database is called 'sur_name':\n```php\n$rules = [\n    'first_name' =\u003e 'unique_with:users, middle_name, last_name = sur_name',\n];\n```\n\n## Example\n\nPretend you have a `users` table in your database plus `User` model like this:\n\n```php\n\u003c?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\n\nclass CreateUsersTable extends Migration {\n\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('users', function(Blueprint $table) {\n            $table-\u003eincrements('id');\n\n            $table-\u003etimestamps();\n\n            $table-\u003estring('first_name');\n            $table-\u003estring('last_name');\n\n            $table-\u003eunique(['first_name', 'last_name']);\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::drop('users');\n    }\n\n}\n```\n\n```php\n\u003c?php\n\nclass User extends Eloquent { }\n```\n\nNow you can validate a given `first_name`, `last_name` combination with something like this:\n\n```php\nRoute::post('test', function() {\n    $rules = [\n        'first_name' =\u003e 'required|unique_with:users,last_name',\n        'last_name' =\u003e 'required',\n    ];\n\n    $validator = Validator::make(Input::all(), $rules);\n\n    if($validator-\u003efails()) {\n        return Redirect::back()-\u003ewithErrors($validator);\n    }\n\n    $user = new User;\n    $user-\u003efirst_name = Input::get('first_name');\n    $user-\u003elast_name = Input::get('last_name');\n    $user-\u003esave();\n\n    return Redirect::home()-\u003ewith('success', 'User created!');\n});\n```\n\nYou can also specify a row id to ignore (useful to solve unique constraint when updating)\n\nThis will ignore row with id 2\n\n```php\n$rules = [\n    'first_name' =\u003e 'required|unique_with:users,last_name,2',\n    'last_name' =\u003e 'required',\n];\n```\n\nTo specify a custom column name for the id, pass it like\n\n```php\n$rules = [\n    'first_name' =\u003e 'required|unique_with:users,last_name,2 = custom_id_column',\n    'last_name' =\u003e 'required',\n];\n```\n\nIf your id is not numeric, you can tell the validator\n\n```php\n$rules = [\n    'first_name' =\u003e 'required|unique_with:users,last_name,ignore:abc123',\n    'last_name' =\u003e 'required',\n];\n```\n\nYou can also set additional clauses. For example, if your model uses soft deleting\nthen you can use the following code to select all existing rows but marked as deleted\n\n```php\n$rules = [\n    'first_name' =\u003e 'required|unique_with:users,last_name,deleted_at,2 = custom_id_column',\n    'last_name' =\u003e 'required',\n];\n```\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliudding%2Funiquewith-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliudding%2Funiquewith-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliudding%2Funiquewith-validator/lists"}