gpt4 book ai didi

laravel - 将两列显示为一列

转载 作者:行者123 更新时间:2023-12-02 00:57:28 25 4
gpt4 key购买 nike

我想选择两列并将其作为一列显示在我的 Controller 中。这是我目前拥有的代码:

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 as 中的代码

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

关于laravel - 将两列显示为一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33030537/

25 4 0
文章推荐: if-statement - Crystal 报表中的多个if else
文章推荐: ruby-on-rails - rails 和 Shopify : Is there any way to see a full list of Shopify API commands?
文章推荐: python - 大矩阵对角化python
文章推荐: html - html