在插入Laravel之前,记录存在于另一个表中

时间:2018-01-27 10:31:37

标签: php laravel

我是Laravel框架的新手,所以请耐心等待,我有两个表用户和received_pa​​y表,挑战是我想首先检查receive_pay的电子邮件和receipt_number,如果他们在注册时与用户输入匹配如果它们匹配则创建新用户否则被拒绝,下面是我的表格详细信息

用户: id,username,email,remember_token,created_at,updated_at

received_pa​​y: id,email,receipt_number

我的用户注册控制器代码是:

protected function create(array $data)
{
    if (Received_pay::where('email', '=', Input::get('email'))->exists()) {
    // user found
        echo "user exist";
     }
    return User::create([
        'username' => $data['username'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'token'   => $data['token'],
    ]);

1 个答案:

答案 0 :(得分:0)

只需更改

Received_pay::where('email', '=', Input::get('email'))->exists()

Received_pay::where('email', '=', Input::get('email'))->where('receipt_number', Input::get('receipt_number'))->exists()

您可以使用多个where()

组合多个条件