2017-09-14 134 views
1

我用两种方式:在Laravel的'join'或'where'中使用'='有什么区别?

$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(); 

和:

$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(); 

,对我来说已经工作过的相同或者添加或删除=迹象。 有人知道这是否允许?如果是这样,那么最好的办法是什么? 谢谢。

回答

5

据源函数定义:

// 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. 

所以你可以看到,如果你忽略了=作为第二个参数,查询生成器将其置于默认情况下,这是一致的你描述的行为。

Reference

相关问题