commit | author | age
|
9f6455
|
1 |
<?php |
DC |
2 |
|
|
3 |
namespace App\Rules; |
|
4 |
|
|
5 |
use Illuminate\Contracts\Validation\Rule; |
|
6 |
|
|
7 |
class MimeType implements Rule |
|
8 |
{ |
|
9 |
/** |
|
10 |
* Create a new rule instance. |
|
11 |
* |
|
12 |
* @return void |
|
13 |
*/ |
|
14 |
public function __construct() |
|
15 |
{ |
|
16 |
|
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* Determine if the validation rule passes. |
|
21 |
* |
|
22 |
* @param string $attribute |
|
23 |
* @param mixed $value |
|
24 |
* @return bool |
|
25 |
*/ |
|
26 |
public function passes($attribute, $value) |
|
27 |
{ |
|
28 |
// Check if there are valid base64 characters |
|
29 |
if (!preg_match('/\w+\/[-+.\w]+/', $value)) { |
|
30 |
return false; |
|
31 |
} |
|
32 |
|
|
33 |
return true; |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Get the validation error message. |
|
38 |
* |
|
39 |
* @return string |
|
40 |
*/ |
|
41 |
public function message() |
|
42 |
{ |
|
43 |
return 'The content_type for the attached binary file must be a MIME Media Type (es: application/pdf)'; |
|
44 |
} |
|
45 |
} |