Jos*_*asi 1 php join where laravel laravel-5
我用过两种方式:
$this->data = DB::table('projects')
->select('companies_info.*', 'project_roles_types.name AS project_role_name')
->join('project_companies_members', 'project_companies_members.project_id', 'projects.project_id')
->where($some_variable, $project_id)
->get();
Run Code Online (Sandbox Code Playgroud)
和:
$this->data = DB::table('projects')
->select('companies_info.*', 'project_roles_types.name AS project_role_name')
->join('project_companies_members', 'project_companies_members.project_id', '=', 'projects.project_id')
->where($some_variable, '=', $project_id)
->get();
Run Code Online (Sandbox Code Playgroud)
对我而言,添加或删除=标志的工作方式相同.有人知道这是否允许?如果是这样,最好的方法是什么?谢谢.
根据源中的函数定义:
// Here we will make some assumptions about the operator. If only 2 values are
// passed to the method, we will assume that the operator is an equals sign
// and keep going. Otherwise, we'll require the operator to be passed in.
Run Code Online (Sandbox Code Playgroud)
因此,您可以看到,如果省略=第二个参数,查询构建器将默认将其放在那里,这与您描述的行为一致.
| 归档时间: |
|
| 查看次数: |
106 次 |
| 最近记录: |