【问题标题】:Merging two tables in Laravel using eloquent使用 eloquent 在 Laravel 中合并两个表
【发布时间】:2022-01-09 02:30:29
【问题描述】:

如何使用 Laravel eloquent 合并两个表,这样如果表 A 中的记录已合并到表 B 中的另一条记录,即使合并条件已合并,它也不能再将 A 中的该记录合并到 B 中的另一条不同记录遇到了吗?任何人都可以帮忙吗?这是我的代码:

class MergedController extends Controller
{  
    public function merged(Request $request){
        $merged=DB::table('client_tutor_request1')
                    ->join('form', 'client_tutor_request1.courses', '=', 'form.specialty')
                    ->whereColumn('form.category', '=', 'client_tutor_request1.category')
                    ->whereColumn('form.state', '=', 'client_tutor_request1.state')
                    ->whereColumn('form.lga', '=', 'client_tutor_request1.lga')
                    ->select('client_tutor_request1.id', 'client_tutor_request1.customers_name', 'client_tutor_request1.customers_phone', 
                    'client_tutor_request1.courses', 'form.employees_name', 'form.state', 'form.lga', 'form.lga', 'form.city',
                     'form.address', 'form.category')
                    ->orderBy('client_tutor_request1.id')
                    ->get();
         
            // return view("employee.linkup", ["merged" => $merged]);
        }
    }
}

【问题讨论】:

    标签: php laravel eloquent backend


    【解决方案1】:

    您可以添加 groupBy('client_tutor_request1.id') 以防止重复记录

    【讨论】:

    • 谢谢。我会试试的。
    猜你喜欢
    • 1970-01-01
    • 2019-09-08
    • 2019-11-17
    • 1970-01-01
    • 2021-04-19
    • 2015-08-11
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多