1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-25 11:52:29 +01:00
freescout/app/Email.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2018-07-10 12:15:58 +02:00
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Email extends Model
{
2018-07-24 08:34:28 +02:00
/**
* Email types.
*/
2018-07-30 17:11:35 +02:00
const TYPE_WORK = 1;
const TYPE_HOME = 2;
const TYPE_OTHER = 3;
public static $types = [
2018-07-30 17:13:33 +02:00
self::TYPE_WORK => 'work',
self::TYPE_HOME => 'home',
2018-07-30 17:11:35 +02:00
self::TYPE_OTHER => 'other',
];
2018-07-10 12:15:58 +02:00
public $timestamps = false;
/**
2018-07-24 08:34:28 +02:00
* Attributes which are not fillable using fill() method.
2018-07-10 12:15:58 +02:00
*/
protected $guarded = ['id', 'customer_id'];
/**
2018-07-24 08:34:28 +02:00
* Get email's customer.
2018-07-10 12:15:58 +02:00
*/
public function customer()
{
return $this->belongsTo('App\Customer');
}
/**
2018-07-30 17:11:35 +02:00
* Sanitize email address.
2018-07-30 17:13:33 +02:00
*
* @param string $email
*
2018-07-24 08:34:28 +02:00
* @return string
2018-07-10 12:15:58 +02:00
*/
2018-07-30 17:11:35 +02:00
public static function sanitizeEmail($email)
2018-07-10 12:15:58 +02:00
{
2018-08-04 17:33:45 +02:00
// FILTER_VALIDATE_EMAIL does not work with long emails for example
// Email validation is not recommended:
// http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address/201378#201378
// So we just check for @
2018-08-04 17:34:46 +02:00
if (!preg_match('/@/', $email)) {
2018-07-30 17:11:35 +02:00
return false;
}
2018-07-10 12:15:58 +02:00
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
2018-08-09 10:14:48 +02:00
$email = mb_strtolower($email, 'UTF-8');
2018-07-30 17:13:33 +02:00
2018-07-10 12:15:58 +02:00
return $email;
}
}