dprh34164 2017-01-09 03:17
浏览 36
已采纳

使用Laravel的auth(5.3),如果表单输入与接受的值不匹配,则阻止注册

I have this reference_id variable that I want to use to bar registration on my site. Basically, if you don't input a reference_id that matches correctly one value among a list (~5-10) values then I want to turn them away. Similarly to how if you only put TEST in the email field it stops you and says "Hey that's not a valid email!'.

Where would I put that logic in? I've pasted my RegisterController below as I think it should go there along with the email logic. I could easily make a variable and do something like

$rfid=reference_id
$list=array(list)
if ($rfid==$list) {
     allow
}
else {
     reject
}

But as you can tell even with that I'm not sure how it would work exactly or where to put it among the rest of the code. Any direction would be appreciated!

RegisterController:

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6|confirmed',
        'reference_id' => 'max:255',

    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'reference_id' => $data['reference_id'],
    ]);
}
  • 写回答

2条回答 默认 最新

  • duanqun7761 2017-01-09 03:35
    关注

    If the reference_id is present in the table you can use

    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
            'reference_id' => 'max:255|exists:table_name',
    
        ]);
    }
    

    If there is an array

    use in_array:$array_name for validation

    For Proper Understanding of available Laravel Validation rule Refer: https://laravel.com/docs/5.3/validation#rule-exists

    Hope This Helps you..

    Lets me know in case of any Query..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教