2017-09-14 92 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

相關問題