I'm initiating in Laravel. I searched and not found how to validate data with some ENUM values. On below code I need that type must be just DEFAULT or SOCIAL. One or other:

$validator = Validator::make(Input::only(['username', 'password', 'type']), [
    'type' => '', // DEFAULT or SOCIAL values
    'username' => 'required|min:6|max:255',
    'password' => 'required|min:6|max:255'
]);

有可能吗?

推荐答案

in:DEFAULT,SOCIAL
The field under validation must be included in the given list of values.

not_in:DEFAULT,SOCIAL
The field under validation must not be included in the given list of values.

$validator = Validator::make(Input::only(['username', 'password', 'type']), [
    'type' => 'in:DEFAULT,SOCIAL', // DEFAULT or SOCIAL values
    'username' => 'required|min:6|max:255',
    'password' => 'required|min:6|max:255'
]);

Laravel相关问答推荐

未将Laravel Blade属性传递给组件或类

将错误消息抛出并显示为关联数组

使用 laravel 根据当月显示注册用户列表

在 laravel 中动态更改时区

Guzzle - Laravel如何使用 x-www-form-url-encoded 发出请求

如何在 Laravel 4 中使用没有 id 的 Eloquent 更新数据

如何使用 Laravel 模型访问数据库视图?

为什么人们将 .env 放入 gitignore?

Laravel Electron邮件验证模板位置

Laravel 4 的 Cron 作业(job)

Laravel 同步错误

WhereNotExists Laravel Eloquent

Laravel db 迁移 - renameColumn 错误 - 请求了未知的数据库类型枚举

扩展 Eloquent 的类的构造函数

Laravel Mail 发送Electron邮件但返回 false

Laravel - 语法错误,文件意外结束

配置和测试 Laravel 任务调度

Laravel 获取查询字符串

Laravel 分页漂亮的 URL

使用 Laravel Mix 合并多个文件