P
P
Pavel2017-08-16 13:42:28
Laravel
Pavel, 2017-08-16 13:42:28

JSON object validation?

There is a POST request, it contains JSON, for example

{
  "User": {
    "name": "Name",
    "lastName": "last name",
    "email": "[email protected]",
  }
}

I'm trying to write validator rules like this
public function rules()
    {
        return [
            'User.name' => 'required|max:100',
            'User.lastName' => 'required|max:100',
            'User.email' => 'required|email|max:255|unique:users',
        ];
    }

everything works fine, except for checking for uniqueness. Laravel is trying to execute a query like this:
select count(*) as aggregate from "users" where "User"."emai" = ?

And, of course, it throws an exception that the "User" table does not exist
Laravel 5.4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Koch, 2017-08-16
@Palych_tw

Write like this:
unique:table,column,except,idColumn

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question