Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<field1> on different place #81

Closed
joeyaurel opened this issue Aug 25, 2017 · 2 comments
Closed

<field1> on different place #81

joeyaurel opened this issue Aug 25, 2017 · 2 comments
Labels

Comments

@joeyaurel
Copy link

joeyaurel commented Aug 25, 2017

I'm currently developing an API and the keys, of the incoming JSON data that have to be validated, do not match the actual database column names.

Incoming JSON for a POST request may look like this:

{
  "data": {
    "attributes": {
      "date": "2017-08-25"
    },
    "relationships": {
      "employee": {
        "set": "202"
      }
    }
  }
}

As the documentation describes I would check if the column date is unique with the column employee_id but I actually would need to check if data.attributes.date is unique with employee_id.

So ...

'<field1>' => 'unique_with:<table>,<field2>[,<field3>,...,<ignore_rowid>]',

... would become ...

'data.attributes.date' => 'unique_with:<table>,employee_id',

Is there any chance that the unique_with validator could look like this: (?)

'<custom_field_name>' => 'unique_with:<table>,<field1>,<field2>[,<field3>,...,<ignore_rowid>]',

Stacktrace:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'data.attributes.date' in 'where clause' (SQL: select count(*) as aggregate from `employees` where `data`.`attributes`.`date` = 2017-08-25)
@felixkiss
Copy link
Owner

You can specify a custom name for the date as in:

$rules = [
    'data.attributes.date' => 'unique_with: employees, data.attributes.date = employed_at, relationships.employee.set = employee_id',
];

@joeyaurel
Copy link
Author

Thanks that worked. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants