我将使用Laravel中的belongsTo、hasMany等方法来连接4个Eloquent模型。
$result = \DB::select(
'ca.*',
array(DB::expr('CONCAT(u.first_name, " ", u.last_name)'), 'user'),
array(DB::expr('CONCAT(u.first_name, " ", u.last_name)'), 'full_name'),
array('u.id','user_id'),
array('d.name','department_name'),
array('d.clean_name','department_clean_name'),
array('d.id','department_id'),
array('u.extension','user_extension'),
array('u.mobile','user_mobile'),
array('u.email','email')
)
->from(array('case_assignments', 'ca'))
->join(array('departments', 'd'), 'left')->on('d.id','=','ca.department_id')
->join(array('users', 'u'), 'left')->on('u.id','=','ca.user_id')
->where('case_id','=', $case_id)
->get();
我该如何将这个转换为Laravel Eloquent关系?