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_VIDEO = 'video'; |
||
18 | const TYPE_SVG = 'svg'; |
||
19 | const TYPE_PDF = 'pdf'; |
||
20 | |||
21 | protected $guarded = ['id', 'disk', 'file_name', 'size', 'model_type', 'model_id']; |
||
22 | |||
23 | /** |
||
24 | * The attributes that should be casted to native types. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $casts = [ |
||
29 | 'manipulations' => 'array', |
||
30 | 'custom_properties' => 'array', |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * Create the polymorphic relation. |
||
35 | * |
||
36 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
37 | */ |
||
38 | public function model() |
||
42 | |||
43 | /** |
||
44 | * Get the original Url to a media-file. |
||
45 | * |
||
46 | * @param string $conversionName |
||
47 | * |
||
48 | * @return string |
||
49 | * |
||
50 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
51 | */ |
||
52 | public function getUrl(string $conversionName = '') : string |
||
62 | |||
63 | /** |
||
64 | * Get the original path to a media-file. |
||
65 | * |
||
66 | * @param string $conversionName |
||
67 | * |
||
68 | * @return string |
||
69 | * |
||
70 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
71 | */ |
||
72 | public function getPath(string $conversionName = '') : string |
||
82 | |||
83 | /** |
||
84 | * Determine the type of a file. |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getTypeAttribute() |
||
97 | |||
98 | /** |
||
99 | * Determine the type of a file from its file extension. |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | public function getTypeFromExtensionAttribute() |
||
125 | |||
126 | /* |
||
127 | * Determine the type of a file from its mime type |
||
128 | */ |
||
129 | public function getTypeFromMimeAttribute() : string |
||
155 | |||
156 | public function getMimeAttribute() : string |
||
160 | |||
161 | public function getExtensionAttribute() : string |
||
165 | |||
166 | public function getHumanReadableSizeAttribute() : string |
||
170 | |||
171 | public function getDiskDriverName() : string |
||
175 | |||
176 | /* |
||
177 | * Determine if the media item has a custom property with the given name. |
||
178 | */ |
||
179 | public function hasCustomProperty(string $propertyName) : bool |
||
183 | |||
184 | /** |
||
185 | * Get if the value of custom property with the given name. |
||
186 | * |
||
187 | * @param string $propertyName |
||
188 | * @param mixed $default |
||
189 | * |
||
190 | * @return mixed |
||
191 | */ |
||
192 | public function getCustomProperty(string $propertyName, $default = null) |
||
196 | |||
197 | /** |
||
198 | * @param string $name |
||
199 | * @param mixed $value |
||
200 | */ |
||
201 | public function setCustomProperty(string $name, $value) |
||
205 | |||
206 | /** |
||
207 | * @param string $name |
||
208 | * |
||
209 | * @return $this |
||
210 | */ |
||
211 | public function removeCustomProperty(string $name) |
||
224 | |||
225 | /* |
||
226 | * Get all the names of the registered media conversions. |
||
227 | */ |
||
228 | public function getMediaConversionNames() : array |
||
236 | } |
||
237 |