显示来自其他表的数据表数据

时间:2020-02-02 08:28:31

标签: laravel-5

我想在我的主表单数据中显示另一个表中的数据表数据。

  1. 公司主文件具有“雇员”选项卡,该选项卡通过数据表显示。
  2. 通过company_id链接到公司的雇员表

该关系已经在所有相关模型中定义,我现在想使用数据表在[公司主数据]内部的[公司员工标签]中显示员工/ p>

我只想过滤/仅显示已打开公司的数据

== 这是CompanyManagementController == [员工]

public function getManagement()
    {

        return DataTables::of(CompanyManagement::query())

            ->editColumn('name', function (CompanyManagement $management) {
                return $management->name;
            })
            ->editColumn('party_id', function (CompanyManagement $management) {
                return $management->party->name;
            })
            ->editColumn('phone', function (CompanyManagement $management) {
                return $management->phone;
            })

            ->editColumn('email', function (CompanyManagement $management) {
                return $management->email;
            })

            ->editColumn('management_role_id', function (CompanyManagement $management) {
                return $management->managementRole->name;
            })

            ->editColumn('additional_info', function (CompanyManagement $management) {
                return $management->additional_info;
            })

            ->rawColumns(['action'])

            ->addColumn('action', function ($id) {
                return '<a href="management/' . $id->id . '" class="btn btn-xs btn-primary ">Edit</a>';
            })


            ->make(true);
    }

**脚本的数据表路由**

Route::get('getmanagement', 'CommpanyManagementController@getManagement')->name('get.management');

**刀片脚本**

        $(function() {
            $('#management').DataTable({
                processing: true,
                serverSide: true,

                ajax: '{!! route('get.management') !!}',
                columns: [
                    { data: 'name', name: 'name' },
                    { data: 'management_role_id', name: 'management_role_id' },
                    { data: 'additional_info', name: 'additional_info' },
                    { data: 'party_id', name: 'party_id' },
                    { data: 'phone', name: 'phone' },
                    { data: 'email', name: 'email' },
                    { data: 'action', name: 'action' }
                ],
            });
        });

0 个答案:

没有答案