代码之家  ›  专栏  ›  技术社区  ›  haffis asma

合并数据表中的两列

  •  2
  • haffis asma  · 技术社区  · 6 年前

    enter image description here

    我想在数据表中组合两列。我有 name surname 但我想把它们组合起来,只显示一列全名。

    刀片

    <th>{{ trans('labels.backend.patients.table.id') }}</th>
    <th>{{ trans('labels.backend.patients.table.nom_patient') }}</th>
    <th>{{ trans('labels.backend.patients.table.prenom_patient') }}</th>
    <th>{{ trans('labels.backend.patients.table.date_naissance') }}</th>
    

    DATABATE AJAX

    columns: [ {data: 'id', name: '{{config('module.patients.table')}}.id'},
        {data: 'nom_patient', name: '{{config('module.patients.table')}}.nom_patient'},
        {data: 'prenom_patient', name: '{{config('module.patients.table')}}.prenom_patient'},
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Stormhammer    6 年前

    在您的情况下,我将在您的模型中创建一个访问器:

    getNomCompletAttribute() {
        return $this->prenom . ' ' . $this->nom;
    }
    

    我相信你现在可以打电话了 nom_complet 就像它是数据表中的常规字段一样。

    Docs: https://laravel.com/docs/5.7/eloquent-mutators#defining-an-accessor

        2
  •  0
  •   haffis asma    6 年前

    我听从你的帮助,试着把主题和那个结合起来

    public function __invoke(ManagePatientRequest $request)
        {
            return Datatables::of($this->patient->getForDataTable())
                ->escapeColumns(['id'])
                ->addColumn('nom_patient', function ($patient) {
                    return $patient->nom_patient.''.$patient->prenom_patient;
                }