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_PDF = 'pdf'; |
||
18 | |||
19 | protected $guarded = ['id', 'disk', 'file_name', 'size', 'model_type', 'model_id']; |
||
20 | |||
21 | /** |
||
22 | * The attributes that should be casted to native types. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $casts = [ |
||
27 | 'manipulations' => 'array', |
||
28 | 'custom_properties' => 'array', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Create the polymorphic relation. |
||
33 | * |
||
34 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
35 | */ |
||
36 | public function model() |
||
40 | |||
41 | /** |
||
42 | * Get the original Url to a media-file. |
||
43 | * |
||
44 | * @param string $conversionName |
||
45 | * |
||
46 | * @return string |
||
47 | * |
||
48 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
49 | */ |
||
50 | public function getUrl(string $conversionName = '') : string |
||
60 | |||
61 | /** |
||
62 | * Get the original path to a media-file. |
||
63 | * |
||
64 | * @param string $conversionName |
||
65 | * |
||
66 | * @return string |
||
67 | * |
||
68 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
69 | */ |
||
70 | public function getPath(string $conversionName = '') : string |
||
80 | |||
81 | /** |
||
82 | * Determine the type of a file. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getTypeAttribute() |
||
95 | |||
96 | /** |
||
97 | * Determine the type of a file from its file extension. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getTypeFromExtensionAttribute() |
||
115 | |||
116 | /* |
||
117 | * Determine the type of a file from its mime type |
||
118 | */ |
||
119 | public function getTypeFromMimeAttribute() : string |
||
137 | |||
138 | public function getExtensionAttribute() : string |
||
142 | |||
143 | public function getHumanReadableSizeAttribute() : string |
||
147 | |||
148 | public function getDiskDriverName() : string |
||
152 | |||
153 | /* |
||
154 | * Determine if the media item has a custom property with the given name. |
||
155 | */ |
||
156 | public function hasCustomProperty(string $propertyName) : bool |
||
160 | |||
161 | /** |
||
162 | * Get if the value of custom property with the given name. |
||
163 | * |
||
164 | * @param string $propertyName |
||
165 | * @param mixed $default |
||
166 | * |
||
167 | * @return mixed |
||
168 | */ |
||
169 | public function getCustomProperty(string $propertyName, $default = null) |
||
173 | |||
174 | /** |
||
175 | * @param string $name |
||
176 | * @param mixed $value |
||
177 | */ |
||
178 | public function setCustomProperty(string $name, $value) |
||
182 | |||
183 | /* |
||
184 | * Get all the names of the registered media conversions. |
||
185 | */ |
||
186 | public function getMediaConversionNames() : array |
||
194 | } |
||
195 |