Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel检查用户是否有用户名如果没有显示用户id excel_Laravel - Fatal编程技术网

Laravel检查用户是否有用户名如果没有显示用户id 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,

我正在使用laravel excel插件

我正在excel中构建映射。如果用户名不存在,如果用户按下载excel文件,则只显示
用户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是可以的