1 | <?php |
||
12 | class Media extends Model |
||
13 | { |
||
14 | use SortableTrait; |
||
15 | |||
16 | const TYPE_OTHER = 'other'; |
||
17 | |||
18 | protected $guarded = []; |
||
19 | |||
20 | /** |
||
21 | * The attributes that should be casted to native types. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $casts = [ |
||
26 | 'manipulations' => 'array', |
||
27 | 'custom_properties' => 'array', |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Create the polymorphic relation. |
||
32 | * |
||
33 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
34 | */ |
||
35 | public function model() |
||
36 | { |
||
37 | return $this->morphTo(); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Get the url to a original media file. |
||
42 | * |
||
43 | * @param string $conversionName |
||
44 | * |
||
45 | * @return string |
||
46 | * |
||
47 | * @throws \Spatie\MediaLibrary\Exceptions\InvalidConversion |
||
48 | */ |
||
49 | public function getUrl(string $conversionName = ''): string |
||
50 | { |
||
51 | $urlGenerator = UrlGeneratorFactory::createForMedia($this); |
||
52 | |||
53 | if ($conversionName !== '') { |
||
54 | $conversion = ConversionCollection::createForMedia($this)->getByName($conversionName); |
||
55 | |||
56 | $urlGenerator->setConversion($conversion); |
||
57 | } |
||
58 | |||
59 | return $urlGenerator->getUrl(); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get the path to the original 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 |
||
72 | { |
||
73 | $urlGenerator = UrlGeneratorFactory::createForMedia($this); |
||
74 | |||
75 | if ($conversionName != '') { |
||
76 | $conversion = ConversionCollection::createForMedia($this)->getByName($conversionName); |
||
77 | |||
78 | $urlGenerator->setConversion($conversion); |
||
79 | } |
||
80 | |||
81 | return $urlGenerator->getPath(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Collection of all ImageGenerator drivers. |
||
86 | */ |
||
87 | public function getImageGenerators() : Collection |
||
91 | |||
92 | /** |
||
93 | * Determine the type of a file. |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getTypeAttribute() |
||
107 | |||
108 | public function getTypeFromExtension(): string |
||
120 | |||
121 | /* |
||
122 | * Determine the type of a file from its mime type |
||
123 | */ |
||
124 | public function getTypeFromMime(): string |
||
136 | |||
137 | public function getExtensionAttribute(): string |
||
141 | |||
142 | public function getHumanReadableSizeAttribute(): string |
||
146 | |||
147 | public function getDiskDriverName(): string |
||
151 | |||
152 | /* |
||
153 | * Determine if the media item has a custom property with the given name. |
||
154 | */ |
||
155 | public function hasCustomProperty(string $propertyName): bool |
||
159 | |||
160 | /** |
||
161 | * Get if the value of custom property with the given name. |
||
162 | * |
||
163 | * @param string $propertyName |
||
164 | * @param mixed $default |
||
165 | * |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function getCustomProperty(string $propertyName, $default = null) |
||
172 | |||
173 | /** |
||
174 | * @param string $name |
||
175 | * @param mixed $value |
||
176 | * |
||
177 | * @return $this |
||
178 | */ |
||
179 | public function setCustomProperty(string $name, $value) |
||
189 | |||
190 | /** |
||
191 | * @param string $name |
||
192 | * |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function forgetCustomProperty(string $name) |
||
205 | |||
206 | /* |
||
207 | * Get all the names of the registered media conversions. |
||
208 | */ |
||
209 | public function getMediaConversionNames(): array |
||
217 | } |
||
218 |