Laravel检查用户是否有用户名如果没有显示用户id excel
我正在使用laravel excel插件 我正在excel中构建映射。如果用户名不存在,如果用户按下载excel文件,则只显示Laravel检查用户是否有用户名如果没有显示用户id excel,laravel,Laravel,我正在使用laravel excel插件 我正在excel中构建映射。如果用户名不存在,如果用户按下载excel文件,则只显示用户id。我试过一些方法,但没有结果 public function map($user): array { return[ $user->id, $user->user->name != $user->user_id, $user->organization->name,
用户id
。我试过一些方法,但没有结果
public function map($user): array
{
return[
$user->id,
$user->user->name != $user->user_id,
$user->organization->name,
$user->course_id,
$user->start_date,
$user->end_date,
$user->completed,
$user->score,
];
}
使用三元演说家
公共函数映射($user):数组
{
返回[
$user->id,
isset($user->user->name)&&&!empty($user->user->name)?$user->user->name:$user->user\u id,
$user->organization->name,
$user->course\u id,
$user->开始日期,
$user->结束日期,
$user->已完成,
$user->score,
];
}
@RonvanderHeiden isset还可以检查密钥是否存在,它在nosql数据库中非常方便,在nosql数据库中仅使用empty将破坏代码,尽管在sql数据库中仅使用empty是可以的