A JOIN With Additional Conditions Using Query Builder or Eloquent

后端 未结 6 696
抹茶落季
抹茶落季 2020-12-04 09:08

I\'m trying to add a condition using a JOIN query with Laravel Query Builder.



        
6条回答
  •  既然无缘
    2020-12-04 09:29

    There's a difference between the raw queries and standard selects (between the DB::raw and DB::select methods).

    You can do what you want using a DB::select and simply dropping in the ? placeholder much like you do with prepared statements (it's actually what it's doing).

    A small example:

    $results = DB::select('SELECT * FROM user WHERE username=?', ['jason']);
    

    The second parameter is an array of values that will be used to replace the placeholders in the query from left to right.

提交回复
热议问题