将两列显示为一列

Display two columns as one

我想 select 两列并在我的控制器中将其显示为一列。这是我目前拥有的代码:

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.FirstNamedbo_students.LastName 合并到一栏中有什么想法吗?

你应该试试 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();
}