how to check one field with two values in laravel 4.2

前端 未结 2 1501
终归单人心
终归单人心 2020-12-07 05:00
$input = Input::all();


$user = User::where(function($q) {
          $q->where(\'email\', $input[\'email\'] )
            ->orWhere(\'email\', $input[\'emails         


        
相关标签:
2条回答
  • 2020-12-07 05:42

    Add use($input) to pass the $input variable to the closure scope:

    User::where(function ($q) use ($input) {
    

    Closures may also inherit variables from the parent scope. Any such variables must be passed to the use language construct.

    http://php.net/manual/en/functions.anonymous.php

    0 讨论(0)
  • 2020-12-07 06:02
    User::where(function($q) use ($input) {
        $q->where('email', $input['emails'][0]['value']);
        if (array_key_exists('email', $input)) {
            $q->orWhere('email', $input['emails'][0]['value']);
        }
    })
    

    but make sure that you always have this value $input['emails'][0]['value']

    0 讨论(0)
提交回复
热议问题