1 | <?php |
||
18 | trait HasMediaTrait |
||
19 | { |
||
20 | /** @var array */ |
||
21 | public $mediaConversions = []; |
||
22 | |||
23 | /** @var bool */ |
||
24 | protected $deletePreservingMedia = false; |
||
25 | |||
26 | public static function bootHasMediaTrait() |
||
27 | { |
||
28 | static::deleted(function (HasMedia $entity) { |
||
29 | if ($entity->shouldDeletePreservingMedia()) { |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | $entity->media()->get()->each->delete(); |
||
34 | }); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Set the polymorphic relation. |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | public function media() |
||
46 | |||
47 | /** |
||
48 | * Add a file to the medialibrary. |
||
49 | * |
||
50 | * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $file |
||
51 | * |
||
52 | * @return \Spatie\MediaLibrary\FileAdder\FileAdder |
||
53 | */ |
||
54 | public function addMedia($file) |
||
58 | |||
59 | /** |
||
60 | * Add a file from a request. |
||
61 | * |
||
62 | * @param string $key |
||
63 | * |
||
64 | * @return \Spatie\MediaLibrary\FileAdder\FileAdder |
||
65 | */ |
||
66 | public function addMediaFromRequest(string $key) |
||
70 | |||
71 | /** |
||
72 | * Add a remote file to the medialibrary. |
||
73 | * |
||
74 | * @param string $url |
||
75 | * |
||
76 | * @return \Spatie\MediaLibrary\FileAdder\FileAdder |
||
77 | * |
||
78 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
79 | */ |
||
80 | public function addMediaFromUrl(string $url) |
||
96 | |||
97 | /** |
||
98 | * Add a base64 encoded file to the medialibrary. |
||
99 | * |
||
100 | * @param string $base64data |
||
101 | * |
||
102 | * @throws InvalidBase64Data |
||
103 | * @throws \Spatie\MediaLibrary\Exceptions\FileCannotBeAdded |
||
104 | * |
||
105 | * @return \Spatie\MediaLibrary\FileAdder\FileAdder |
||
106 | */ |
||
107 | public function addMediaFromBase64(string $base64data) |
||
136 | |||
137 | /** |
||
138 | * Copy a file to the medialibrary. |
||
139 | * |
||
140 | * @param string|\Symfony\Component\HttpFoundation\File\UploadedFile $file |
||
141 | * |
||
142 | * @return \Spatie\MediaLibrary\FileAdder\FileAdder |
||
143 | */ |
||
144 | public function copyMedia($file) |
||
148 | |||
149 | /* |
||
150 | * Determine if there is media in the given collection. |
||
151 | */ |
||
152 | public function hasMedia(string $collectionName = 'default'): bool |
||
156 | |||
157 | /** |
||
158 | * Get media collection by its collectionName. |
||
159 | * |
||
160 | * @param string $collectionName |
||
161 | * @param array|callable $filters |
||
162 | * |
||
163 | * @return \Illuminate\Support\Collection |
||
164 | */ |
||
165 | public function getMedia(string $collectionName = 'default', $filters = []): Collection |
||
169 | |||
170 | /** |
||
171 | * Get the first media item of a media collection. |
||
172 | * |
||
173 | * @param string $collectionName |
||
174 | * @param array $filters |
||
175 | * |
||
176 | * @return Media|null |
||
177 | */ |
||
178 | public function getFirstMedia(string $collectionName = 'default', array $filters = []) |
||
184 | |||
185 | /* |
||
186 | * Get the url of the image for the given conversionName |
||
187 | * for first media for the given collectionName. |
||
188 | * If no profile is given, return the source's url. |
||
189 | */ |
||
190 | public function getFirstMediaUrl(string $collectionName = 'default', string $conversionName = ''): string |
||
200 | |||
201 | /* |
||
202 | * Get the url of the image for the given conversionName |
||
203 | * for first media for the given collectionName. |
||
204 | * If no profile is given, return the source's url. |
||
205 | */ |
||
206 | public function getFirstMediaPath(string $collectionName = 'default', string $conversionName = ''): string |
||
216 | |||
217 | /** |
||
218 | * Update a media collection by deleting and inserting again with new values. |
||
219 | * |
||
220 | * @param array $newMediaArray |
||
221 | * @param string $collectionName |
||
222 | * |
||
223 | * @return \Illuminate\Support\Collection |
||
224 | * |
||
225 | * @throws \Spatie\MediaLibrary\Exceptions\MediaCannotBeUpdated |
||
226 | */ |
||
227 | public function updateMedia(array $newMediaArray, string $collectionName = 'default'): Collection |
||
257 | |||
258 | /** |
||
259 | * @param array $newMediaArray |
||
260 | * @param string $collectionName |
||
261 | */ |
||
262 | protected function removeMediaItemsNotPresentInArray(array $newMediaArray, string $collectionName = 'default') |
||
270 | |||
271 | /** |
||
272 | * Remove all media in the given collection. |
||
273 | * |
||
274 | * @param string $collectionName |
||
275 | * |
||
276 | * @return $this |
||
277 | */ |
||
278 | public function clearMediaCollection(string $collectionName = 'default') |
||
294 | |||
295 | /** |
||
296 | * Delete the associated media with the given id. |
||
297 | * You may also pass a media object. |
||
298 | * |
||
299 | * @param int|\Spatie\MediaLibrary\Media $mediaId |
||
300 | * |
||
301 | * @throws \Spatie\MediaLibrary\Exceptions\MediaCannotBeDeleted |
||
302 | */ |
||
303 | public function deleteMedia($mediaId) |
||
317 | |||
318 | /* |
||
319 | * Add a conversion. |
||
320 | */ |
||
321 | public function addMediaConversion(string $name): Conversion |
||
329 | |||
330 | /** |
||
331 | * Delete the model, but preserve all the associated media. |
||
332 | * |
||
333 | * @return bool |
||
334 | */ |
||
335 | public function deletePreservingMedia(): bool |
||
341 | |||
342 | /** |
||
343 | * Determines if the media files should be preserved when the media object gets deleted. |
||
344 | * |
||
345 | * @return \Spatie\MediaLibrary\Media |
||
346 | */ |
||
347 | public function shouldDeletePreservingMedia() |
||
351 | |||
352 | protected function mediaIsPreloaded(): bool |
||
356 | |||
357 | /** |
||
358 | * Cache the media on the object. |
||
359 | * |
||
360 | * @param string $collectionName |
||
361 | * |
||
362 | * @return mixed |
||
363 | */ |
||
364 | public function loadMedia(string $collectionName) |
||
389 | } |
||
390 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.