1 | <?php |
||
11 | class Media extends Model |
||
12 | { |
||
13 | use SortableTrait; |
||
14 | |||
15 | const TYPE_OTHER = 'other'; |
||
16 | const TYPE_IMAGE = 'image'; |
||
17 | const TYPE_SVG = 'svg'; |
||
18 | const TYPE_PDF = 'pdf'; |
||
19 | |||
20 | protected $guarded = ['id', 'disk', 'file_name', 'size', 'model_type', 'model_id']; |
||
21 | |||
22 | /** |
||
23 | * The attributes that should be casted to native types. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $casts = [ |
||
28 | 'manipulations' => 'array', |
||
29 | 'custom_properties' => 'array', |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * Create the polymorphic relation. |
||
34 | * |
||
35 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
36 | */ |
||
37 | public function model() |
||
41 | |||
42 | /** |
||
43 | * Get the original Url to a media-file. |
||
44 | * |
||
45 | * @param string $conversionName |
||
46 | * |
||
47 | * @return string |
||
48 | * |
||
49 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
50 | */ |
||
51 | public function getUrl(string $conversionName = '') : string |
||
61 | |||
62 | /** |
||
63 | * Get the original path to a media-file. |
||
64 | * |
||
65 | * @param string $conversionName |
||
66 | * |
||
67 | * @return string |
||
68 | * |
||
69 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
70 | */ |
||
71 | public function getPath(string $conversionName = '') : string |
||
81 | |||
82 | /** |
||
83 | * Determine the type of a file. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getTypeAttribute() |
||
96 | |||
97 | /** |
||
98 | * Determine the type of a file from its file extension. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function getTypeFromExtensionAttribute() |
||
120 | |||
121 | /* |
||
122 | * Determine the type of a file from its mime type |
||
123 | */ |
||
124 | public function getTypeFromMimeAttribute() : string |
||
146 | |||
147 | public function getExtensionAttribute() : string |
||
151 | |||
152 | public function getHumanReadableSizeAttribute() : string |
||
156 | |||
157 | public function getDiskDriverName() : string |
||
161 | |||
162 | /* |
||
163 | * Determine if the media item has a custom property with the given name. |
||
164 | */ |
||
165 | public function hasCustomProperty(string $propertyName) : bool |
||
169 | |||
170 | /** |
||
171 | * Get if the value of custom property with the given name. |
||
172 | * |
||
173 | * @param string $propertyName |
||
174 | * @param mixed $default |
||
175 | * |
||
176 | * @return mixed |
||
177 | */ |
||
178 | public function getCustomProperty(string $propertyName, $default = null) |
||
182 | |||
183 | /** |
||
184 | * @param string $name |
||
185 | * @param mixed $value |
||
186 | */ |
||
187 | public function setCustomProperty(string $name, $value) |
||
191 | |||
192 | /* |
||
193 | * Get all the names of the registered media conversions. |
||
194 | */ |
||
195 | public function getMediaConversionNames() : array |
||
203 | } |
||
204 |