如何在数据库中设置其ID时,如何在Excel中打印用户的名称。 PHP,Laravel
我从基于Laravel框架的网页中导出一个表来优化,但是当我下载它下载的文件时。
但是我想在这些文件中显示与特定的id相对应的用户名。 同样的项目。 (但是如果为用户名find解决scheme,也可以为项目使用同样的解决scheme)。
您需要根据Timesheets表中的user_id创build一个join您的用户表。 将你的雄辩查询修改为:
$data = Timesheet::select('timesheets.name', 'timesheets.description', 'timesheets.project_id', 'users.fullName', 'timesheets.hours', 'timesheets.date', 'timesheets.created_at', 'timesheets.updated_at') ->join('users', 'timesheets.user_id', '=', 'users.id') ->get()->toArray();
我还指定了特定的列,以便您可以完全控制电子表格中显示的数据。
我看到你也有project_id ,所以你会想要添加另一个join()方法到您的查询项目表来处理。