Laravel how to get query with bindings?

前端 未结 14 703
小蘑菇
小蘑菇 2021-01-31 15:58

I have some query that I need to pass to another query using query builder

$query = DB::table(\'table\')->whereIn(\'some_field\', [1,2,30])->toSql();

Mode         


        
相关标签:
14条回答
  • 2021-01-31 16:50

    Laravel now offers debugging directly on your Builder!!!

    https://laravel.com/docs/queries#debugging

    \App\User::where('age', '18')->dump();
    \App\User::where('age', '18')->dd();
    

    Outputs

    "select * from `users` where `age` = ?"
    [
        0 => "18"
    ]
    
    0 讨论(0)
  • 2021-01-31 16:52

    Check out the getBindings() method on the Builder class

    getBindings()

    $query = DB::table('table')->whereIn('some_field', [1,2,30]);
    
    $sql = $query->toSql();
    
    $bindings = $query->getBindings();
    
    0 讨论(0)
提交回复
热议问题