Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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 Excel验证不同于数据库列名的标题行_Laravel_Laravel Excel_Laravel 6 - Fatal编程技术网

使用Laravel Excel验证不同于数据库列名的标题行

使用Laravel Excel验证不同于数据库列名的标题行,laravel,laravel-excel,laravel-6,Laravel,Laravel Excel,Laravel 6,我正在使用以下程序包导入excel文件,但在验证行时遇到问题 标题行名称可能与数据库中的列名不同。因此,我的问题是如何验证具有不同名称的标题行?例如,数据库列名为first\u name,但标题行名称可以是first\u name或voornaam 我还想知道为什么:message没有使用语言文件中的本地化:attribute。例如,属性first\u name在lang/nl/validation.php中被翻译为voornaam错误消息仍然返回first\u name 导入功能: publi

我正在使用以下程序包导入excel文件,但在验证行时遇到问题

标题行名称可能与数据库中的列名不同。因此,我的问题是如何验证具有不同名称的标题行?例如,数据库列名为
first\u name
,但标题行名称可以是
first\u name
voornaam

我还想知道为什么
:message
没有使用语言文件中的本地化
:attribute
。例如,属性
first\u name
在lang/nl/validation.php中被翻译为
voornaam
错误消息仍然返回
first\u name

导入功能:

public function model( array $row )
{
        return new Participant([
            'salutation' => $row['salutation'] ?? $row['aanhef'] ?? null,
            'first_name' => $row['first_name'] ?? $row['voornaam'] ?? $row['voorletters'] ?? $row['voorletter'],
            'last_name' => $row['last_name'] ?? $row['achternaam']
     ]);
}
验证规则:

public function rules(): array
{
        return [
            'salutation' => 'nullable|string',
            'first_name' => 'required|string',
            'last_name' => 'required|string',
       ]
}
我曾尝试使用
CustomValidationAttribute
,但这不起作用。也对此事发表了评论,但到目前为止没有回应

public function customValidationAttributes()
{
    return [
        'salutation' => 'salutation',
        'aanhef' => 'salutation',
        'first_name' => 'first_name',
        'voornaam' => 'first_name',
        'last_name' => 'last_name',
        'achternaam' => 'last_name'
     ]
 }

您是否找到了规范化这些列名的解决方案?我认为您可以使用公共函数prepareForValidation(数组$row){return['sallation'=>$row['sallation']??$row['aanhef']???null,]}此方法在规则()之前调用