Laravel validation exists where NOT

后端 未结 6 1829
温柔的废话
温柔的废话 2021-02-04 04:58

Based on the documentations. Exists can have 4 parameters:

exists:table,id,where,0

The question is, What if I wanted it to be where is not. Lik

6条回答
  •  情书的邮戳
    2021-02-04 05:28

    You can use something like this:

    Validator::extend('not_exists', function($attribute, $value, $parameters)
    {
        return DB::table($parameters[0])
            ->where($parameters[1], '=', $value)
            ->andWhere($parameters[2], '<>', $value)
            ->count()<1;
    });
    

提交回复
热议问题