-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
641123e
commit 4c72663
Showing
7 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class EmailListRequest extends FormRequest | ||
{ | ||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'emails' => 'required|array|max:10', | ||
'emails.*.email' => 'required|email', | ||
]; | ||
} | ||
|
||
public function messages() | ||
{ | ||
return [ | ||
'emails.*.email' => 'List of recipients contains an invalid email address: :input', | ||
]; | ||
} | ||
|
||
/** | ||
* Prepare the data for validation. | ||
* | ||
* @return void | ||
*/ | ||
protected function prepareForValidation() | ||
{ | ||
$this->merge([ | ||
'emails' => $this->extractEmailAddresses($this->emails), | ||
]); | ||
} | ||
|
||
private function extractEmailAddresses($input) | ||
{ | ||
return collect(explode(',', $input))->map(function ($line) { | ||
// Attempt to match line in the format "FirstName Surname" <[email protected]> | ||
if (preg_match('/(?:"?([^"^\s]*)\s?([^"]*)?"?\s)?(?:<?(.+@[^>]+)>?)/', $line, $matches)) { | ||
return ['email' => $matches[3], 'forename' => $matches[1], 'surname' => $matches[2]]; | ||
} else { | ||
return ['email' => $line]; | ||
} | ||
})->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters