如何比较两个表数据并将其存储在Laravel中

时间:2018-11-20 20:43:11

标签: php sql database laravel join

您好,我正在网站的“管理”部分的帮助下进行重置密码,但是现在我遇到了一个问题。实际上,我不知道如何将两个表相互比较,如果它们匹配,那么如何将该请求存储到另一张桌子。这是两个表的架构。用户表

Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->string('weight');
        $table->string('height');
        $table->string('gender');
        $table->date('dob');
        $table->rememberToken();
        $table->timestamps();
    });

忘记密码请求表

 Schema::create('Forgot_Passwords', function (Blueprint $table) {
    $table->increments('id');
        $table->string('email');
        $table->string('password');
        $table->string('weight');
        $table->string('height');
        $table->rememberToken();
        $table->timestamps();
         });

我必须使两个表的电子邮件,重量和高度相互匹配。

1 个答案:

答案 0 :(得分:0)

我认为您输入的是电子邮件。

$user = User::where('email', $email)->first();
$forgotPassword = ForgotPassword::where('email', $email)->first();

$if(($user->email == $forgotPassword->email) and ($user->weight == $forgotPassword->weight) and ($user->height == $forgotPassword->height)  { 
   // some insert code here
}

希望这能给您带来想法。