Skip to content

Commit

Permalink
import file extension validation
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Feb 28, 2020
1 parent e54ee59 commit 03111fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Requests/Common/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function authorize()
public function rules()
{
return [
'import' => 'required|file',
'import' => 'required|file|extension:xls,xlsx',
];
}
}
8 changes: 8 additions & 0 deletions app/Providers/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function boot()
},
trans('validation.custom.invalid_amount', ['attribute' => $amount])
);

Validator::extend('extension', function ($attribute, $value, $parameters, $validator) {
$extension = $value->getClientOriginalExtension();

return !empty($extension) && in_array($extension, $parameters);
},
trans('validation.custom.invalid_extension')
);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions resources/lang/en-GB/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@

'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
'rule-name' => 'custom-message',
],
'invalid_currency' => 'The :attribute code is invalid.',
'invalid_amount' => 'The amount :attribute is invalid.',
'invalid_currency' => 'The :attribute code is invalid.',
'invalid_amount' => 'The amount :attribute is invalid.',
'invalid_extension' => 'The file extension is invalid.',
],

/*
Expand Down

0 comments on commit 03111fe

Please sign in to comment.