我想选择两列并在控制器中将其显示为一列。这是我目前的代码:
public function assignment()
{
$title = "View Parent Assignment";
$vpc = DB::table('dbo_guardianchild')
->join('dbo_students', 'dbo_guardianchild.StudentID', '=' , 'dbo_students.StudentID')
->join('dbo_guardianinformation' , 'dbo_guardianchild.GuardianInformationID' , '=' , 'dbo_guardianinformation.GuardianInformationID')
->select('dbo_students.StudentID' , 'dbo_students.FirstName AS sFname' , 'dbo_students.LastName AS sLname')
->get();
}
关于如何将dbo_students.FirstName
和dbo_students.LastName
合并为一列的任何想法?
答案 0 :(得分:4)
你应该尝试DB :: raw。尝试将select中的代码替换为
->select(DB::raw('dbo_students.StudentID' ,'CONCAT(dbo_students.FirstName, " ", dbo_students.LastName) AS full_name'))
您的最终代码将是
public function assignment()
{
$title = "View Parent Assignment";
$vpc = DB::table('dbo_guardianchild')
->join('dbo_students', 'dbo_guardianchild.StudentID', '=' , 'dbo_students.StudentID')
->join('dbo_guardianinformation' , 'dbo_guardianchild.GuardianInformationID' , '=' , 'dbo_guardianinformation.GuardianInformationID')
->select(DB::raw('dbo_students.StudentID' ,'CONCAT(dbo_students.FirstName, " ", dbo_students.LastName) AS full_name'))
->get();
}