-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathrepomix-output.xml
More file actions
10491 lines (8825 loc) · 360 KB
/
Copy pathrepomix-output.xml
File metadata and controls
10491 lines (8825 loc) · 360 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This file is a merged representation of a subset of the codebase, containing files not matching ignore patterns, combined into a single document by Repomix.
<file_summary>
This section contains a summary of this file.
<purpose>
This file contains a packed representation of the entire repository's contents.
It is designed to be easily consumable by AI systems for analysis, code review,
or other automated processes.
</purpose>
<file_format>
The content is organized as follows:
1. This summary section
2. Repository information
3. Directory structure
4. Repository files (if enabled)
5. Multiple file entries, each consisting of:
- File path as an attribute
- Full contents of the file
</file_format>
<usage_guidelines>
- This file should be treated as read-only. Any changes should be made to the
original repository files, not this packed version.
- When processing this file, use the file path to distinguish
between different files in the repository.
- Be aware that this file may contain sensitive information. Handle it with
the same level of security as you would the original repository.
</usage_guidelines>
<notes>
- Some files may have been excluded based on .gitignore rules and Repomix's configuration
- Binary files are not included in this packed representation. Please refer to the Repository Structure section for a complete list of file paths, including binary files
- Files matching these patterns are excluded: **/*.log, tmp/, .js, .html, .blade.php, .css, public/, vendor/, node_modules, venv/, logs/, electorn-sentinerl/
- Files matching patterns in .gitignore are excluded
- Files matching default ignore patterns are excluded
- Files are sorted by Git change count (files with more changes are at the bottom)
</notes>
</file_summary>
<directory_structure>
.claude/
settings.local.json
.github/
ISSUE_TEMPLATE/
bug.yml
config.yml
workflows/
dependabot-auto-merge.yml
fix-php-code-styling.yml
tests.yml
CONTRIBUTING.md
dependabot.yml
FUNDING.yml
SECURITY.md
config/
filament-media-manager.php
database/
migrations/
2024_09_28_143941_add_media_if_not_exists_table.php
2024_10_03_171807_create_folders_table.php
2024_10_03_171808_create_media_has_models_table.php
2024_10_03_171809_create_folder_has_models_table.php
2024_10_03_171810_update_folders_table.php
2024_10_20_000000_add_order_column_to_media_has_models_table.php
2024_10_21_000000_add_collection_name_to_media_has_models_table.php
docs/
TRAITS.md
resources/
lang/
ar/
messages.php
en/
messages.php
ru/
messages.php
tr/
messages.php
views/
columns/
media-preview.blade.php
components/
folder-action-view.blade.php
media-picker-modal.blade.php
forms/
media-manager-picker.blade.php
livewire/
folder-component.blade.php
media-picker.blade.php
pages/
folders.blade.php
media.blade.php
routes/
api.php
src/
Console/
FilamentMediaManagerInstall.php
Facade/
FilamentMediaManager.php
Form/
FileInput.php
MediaManagerInput.php
MediaManagerPicker.php
Http/
Controllers/
FolderController.php
Resources/
FolderResource.php
FoldersResource.php
MediaResource.php
Livewire/
FolderComponent.php
MediaPicker.php
Models/
Folder.php
Media.php
Resources/
Actions/
CreateMediaAction.php
CreateSubFolderAction.php
DeleteFolderAction.php
EditCurrentFolderAction.php
FolderResource/
Pages/
CreateFolder.php
EditFolder.php
ListFolders.php
MediaResource/
Pages/
CreateMedia.php
EditMedia.php
ListMedia.php
FolderResource.php
MediaResource.php
Services/
Contracts/
MediaManagerType.php
FilamentMediaManagerServices.php
Traits/
InteractsWithMediaFolders.php
InteractsWithMediaManager.php
FilamentMediaManagerPlugin.php
FilamentMediaManagerServiceProvider.php
tests/
database/
factories/
FolderFactory.php
ProductFactory.php
UserFactory.php
migrations/
2025_10_07_000001_create_products_table.php
src/
Models/
Product.php
User.php
AdminPanelProvider.php
DebugTest.php
FolderResourceTest.php
InteractsWithMediaManagerTest.php
LivewireComponentTest.php
MediaManagerInputTest.php
MediaManagerPickerTest.php
MediaResourceTest.php
PluginTest.php
ProtectedFolderTest.php
TestCase.php
Pest.php
README.md
.gitignore
.php-cs-fixer.dist.php
CHANGELOG.md
CODE_OF_CONDUCT.md
composer.json
fadymondy-tomato-media-manager.md
LICENSE.md
module.json
phpstan.neon
phpunit.xml
pint.json
README.md
testbench.yaml
</directory_structure>
<files>
This section contains the contents of the repository's files.
<file path=".claude/settings.local.json">
{
"permissions": {
"allow": [
"Bash(tree -L 3 /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src -I \"node_modules\")",
"Bash(vendor/bin/pint /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src/Traits/InteractsWithMediaManager.php)",
"Bash(composer test)",
"Bash(vendor/bin/pint /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src/Traits/InteractsWithMediaManager.php /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src/Livewire/MediaPicker.php /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src/Form/MediaManagerPicker.php)",
"Bash(php artisan make:migration add_collection_name_to_media_has_models_table --path=database/migrations --no-interaction)",
"Bash(vendor/bin/pint /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src/Traits/InteractsWithMediaManager.php /Users/fadymondy/Sites/3x1/vendor/tomatophp/filament-media-manager/src/Form/MediaManagerPicker.php)"
]
},
"enableAllProjectMcpServers": true,
"enabledMcpjsonServers": [
"laravel-boost",
"herd",
"puppeteer"
]
}
</file>
<file path="database/migrations/2024_10_21_000000_add_collection_name_to_media_has_models_table.php">
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('media_has_models', function (Blueprint $table) {
$table->string('collection_name')->nullable()->after('media_id');
$table->boolean('responsive_images')->default(false)->after('collection_name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('media_has_models', function (Blueprint $table) {
$table->dropColumn(['collection_name', 'responsive_images']);
});
}
};
</file>
<file path=".github/ISSUE_TEMPLATE/bug.yml">
name: Bug Report
description: Report an Issue or Bug with the Package
title: "[Bug]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
- type: textarea
id: what-happened
attributes:
label: What happened?
description: What did you expect to happen?
placeholder: I cannot currently do X thing because when I do, it breaks X thing.
validations:
required: true
- type: textarea
id: how-to-reproduce
attributes:
label: How to reproduce the bug
description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
placeholder: When I do X I see Y.
validations:
required: true
- type: input
id: package-version
attributes:
label: Package Version
description: What version of our Package are you running? Please be as specific as possible
placeholder: 2.0.0
validations:
required: true
- type: input
id: php-version
attributes:
label: PHP Version
description: What version of PHP are you running? Please be as specific as possible
placeholder: 8.2.0
validations:
required: true
- type: input
id: laravel-version
attributes:
label: Laravel Version
description: What version of Laravel are you running? Please be as specific as possible
placeholder: 9.0.0
validations:
required: true
- type: dropdown
id: operating-systems
attributes:
label: Which operating systems does with happen with?
description: You may select more than one.
multiple: true
options:
- macOS
- Windows
- Linux
- type: textarea
id: notes
attributes:
label: Notes
description: Use this field to provide any other notes that you feel might be relevant to the issue.
validations:
required: false
</file>
<file path=".github/ISSUE_TEMPLATE/config.yml">
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/tomatophp/filament-media-manager/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/tomatophp/filament-media-manager/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/tomatophp/filament-media-manager/security/policy
about: Learn how to notify us for sensitive bugs
</file>
<file path=".github/workflows/dependabot-auto-merge.yml">
name: dependabot-auto-merge
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.4.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
</file>
<file path=".github/CONTRIBUTING.md">
# Contributing
Contributions are **welcome** and will be fully **credited**.
Please read and understand the contribution guide before creating an issue or pull request.
## Etiquette
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skills, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
## Viability
When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.
## Procedure
Before filing an issue:
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.
Before submitting a pull request:
- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
## Requirements
If the project maintainer has any additional requirements, you will find them listed here.
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
**Happy coding**!
</file>
<file path=".github/dependabot.yml">
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
</file>
<file path=".github/SECURITY.md">
# Security Policy
If you discover any security related issues, please email info@3x1.io instead of using the issue tracker.
</file>
<file path="database/migrations/2024_09_28_143941_add_media_if_not_exists_table.php">
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (! Schema::hasTable('media')) {
Schema::create('media', function (Blueprint $table) {
$table->id();
$table->morphs('model');
$table->uuid()->nullable()->unique();
$table->string('collection_name');
$table->string('name');
$table->string('file_name');
$table->string('mime_type')->nullable();
$table->string('disk');
$table->string('conversions_disk')->nullable();
$table->unsignedBigInteger('size');
$table->json('manipulations');
$table->json('custom_properties');
$table->json('generated_conversions');
$table->json('responsive_images');
$table->unsignedInteger('order_column')->nullable()->index();
$table->nullableTimestamps();
});
}
}
};
</file>
<file path="database/migrations/2024_10_03_171810_update_folders_table.php">
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('folders', function (Blueprint $table) {
$table->boolean('is_public')->default(true)->nullable();
$table->boolean('has_user_access')->default(false)->nullable();
$table->unsignedBigInteger('user_id')->nullable();
$table->string('user_type')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('folders', function (Blueprint $table) {
$table->dropColumn('is_public');
$table->dropColumn('has_user_access');
$table->dropColumn('user_id');
$table->dropColumn('user_type');
});
}
};
</file>
<file path="database/migrations/2024_10_20_000000_add_order_column_to_media_has_models_table.php">
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('media_has_models', function (Blueprint $table) {
$table->unsignedInteger('order_column')->nullable()->after('media_id');
$table->index('order_column');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('media_has_models', function (Blueprint $table) {
$table->dropIndex(['order_column']);
$table->dropColumn('order_column');
});
}
};
</file>
<file path="docs/TRAITS.md">
# Media Manager Traits
## InteractsWithMediaManager
The `InteractsWithMediaManager` trait provides convenient methods to interact with media attached to your models via both **MediaManagerPicker** and **MediaManagerInput** (Spatie Media Library).
### Installation
Add the trait to your model:
```php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use TomatoPHP\FilamentMediaManager\Traits\InteractsWithMediaManager;
class Product extends Model
{
use InteractsWithMediaManager;
// ... your model code
}
```
---
## Available Methods
### 1. Get All Media (MediaManagerPicker)
Get all media attached to the model via MediaManagerPicker:
```php
$product = Product::find(1);
$mediaItems = $product->getMediaManagerMedia();
// Get media filtered by field name (if stored in custom properties)
$avatarMedia = $product->getMediaManagerMedia('avatar');
```
**Returns:** `Illuminate\Database\Eloquent\Collection` of Media models
---
### 2. Get Media by UUIDs
Get specific media items by their UUIDs:
```php
$uuids = ['uuid-1', 'uuid-2', 'uuid-3'];
$mediaItems = $product->getMediaManagerMediaByUuids($uuids);
```
**Returns:** `Illuminate\Database\Eloquent\Collection` of Media models
---
### 3. Get Media from Spatie Collection (MediaManagerInput)
Get media from a Spatie Media Library collection:
```php
// Get all media from 'images' collection
$images = $product->getMediaManagerInputMedia('images');
// Get from default collection
$defaultMedia = $product->getMediaManagerInputMedia();
```
**Returns:** `Illuminate\Database\Eloquent\Collection` of Media models
---
### 4. Attach Media
Attach media to the model programmatically:
```php
$uuids = ['uuid-1', 'uuid-2'];
$product->attachMediaManagerMedia($uuids);
```
---
### 5. Detach Media
Detach specific media or all media:
```php
// Detach specific media
$product->detachMediaManagerMedia(['uuid-1', 'uuid-2']);
// Detach all media
$product->detachMediaManagerMedia();
```
---
### 6. Sync Media
Replace all existing media with new media (detach all, then attach new):
```php
$newUuids = ['uuid-3', 'uuid-4', 'uuid-5'];
$product->syncMediaManagerMedia($newUuids);
```
---
### 7. Check if Media Exists
Check if a specific media is attached to the model:
```php
if ($product->hasMediaManagerMedia('uuid-1')) {
// Media is attached
}
```
**Returns:** `bool`
---
### 8. Get First Media
Get the first media item attached to the model:
```php
$firstMedia = $product->getFirstMediaManagerMedia();
if ($firstMedia) {
echo $firstMedia->name;
}
```
**Returns:** `Media|null`
---
### 9. Get Media URL
Get the URL of the first media item:
```php
// Get original URL
$url = $product->getMediaManagerUrl();
// Get URL of a specific conversion
$thumbUrl = $product->getMediaManagerUrl('thumb');
```
**Returns:** `string|null`
---
### 10. Get All Media URLs
Get URLs of all media items:
```php
// Get all original URLs
$urls = $product->getMediaManagerUrls();
// Get all thumbnail URLs
$thumbUrls = $product->getMediaManagerUrls('thumb');
```
**Returns:** `array`
---
## Usage Examples
### Example 1: Display Product Images
```php
@php
$product = App\Models\Product::find(1);
$images = $product->getMediaManagerMedia();
@endphp
<div class="product-gallery">
@foreach($images as $image)
<img src="{{ $image->getUrl('thumb') }}" alt="{{ $image->name }}">
@endforeach
</div>
```
### Example 2: Display User Avatar
```php
@php
$user = auth()->user();
$avatarUrl = $user->getMediaManagerUrl('avatar-thumb') ?? '/default-avatar.png';
@endphp
<img src="{{ $avatarUrl }}" alt="User Avatar" class="avatar">
```
### Example 3: Attach Media in Controller
```php
public function attachFiles(Request $request, Product $product)
{
$mediaUuids = $request->input('media_uuids');
$product->attachMediaManagerMedia($mediaUuids);
return back()->with('success', 'Files attached successfully');
}
```
### Example 4: Sync Media on Update
```php
public function update(Request $request, Product $product)
{
$product->update($request->only(['name', 'description']));
// Sync media (replace all existing with new selection)
if ($request->has('gallery_media')) {
$product->syncMediaManagerMedia($request->input('gallery_media'));
}
return back()->with('success', 'Product updated successfully');
}
```
### Example 5: Check and Display
```php
@if($product->hasMediaManagerMedia($specificUuid))
<div class="badge">Featured Image Set</div>
@endif
@php
$featuredImage = $product->getFirstMediaManagerMedia();
@endphp
@if($featuredImage)
<img src="{{ $featuredImage->getUrl() }}" alt="Featured">
@endif
```
---
## Notes
- All methods that query media bypass the global `folder` scope to ensure you get the correct media
- The `attachMediaManagerMedia()` method uses `updateOrInsert` to prevent duplicates
- Media URLs can be generated with conversions (e.g., `thumb`, `medium`, `large`) if configured in Spatie Media Library
- The trait works with both **MediaManagerPicker** (form component) and **MediaManagerInput** (Spatie collections)
---
## Advanced: Custom Field Names
You can store a field name in the media's custom properties to distinguish between different picker fields:
```php
// When saving, store the field name
$media->setCustomProperty('field_name', 'avatar');
$media->save();
// Later, retrieve only avatar media
$avatarMedia = $user->getMediaManagerMedia('avatar');
```
This is useful when a model has multiple MediaManagerPicker fields and you need to distinguish between them programmatically.
</file>
<file path="resources/views/components/media-picker-modal.blade.php">
@livewire('media-picker', [
'pickerKey' => $pickerKey,
'isMultiple' => $isMultiple,
'collectionName' => $collectionName,
'maxItems' => $maxItems ?? null,
'minItems' => $minItems ?? null,
'initialState' => $currentState ?? null,
])
</file>
<file path="resources/views/livewire/folder-component.blade.php">
<div>
{{ ($this->getFolderAction)(['item' => $item]) }}
<x-filament-actions::modals />
</div>
</file>
<file path="src/Http/Resources/FoldersResource.php">
<?php
namespace TomatoPHP\FilamentMediaManager\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class FoldersResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'color' => $this->color,
'icon' => $this->icon,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}
</file>
<file path="src/Livewire/FolderComponent.php">
<?php
namespace TomatoPHP\FilamentMediaManager\Livewire;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Livewire\Component;
class FolderComponent extends Component implements HasActions, HasSchemas
{
use InteractsWithActions;
use InteractsWithSchemas;
public $item;
public function mount($item): void
{
$this->item = $item;
}
public function getFolderAction(): Action
{
return Action::make('getFolderAction')
->color('danger')
->view('filament-media-manager::components.folder-action-view', fn (array $arguments) => ['item' => $arguments['item']])
->requiresConfirmation(function (array $arguments) {
if (isset($arguments['item'])) {
if ($arguments['item']['is_protected']) {
return true;
} else {
return false;
}
}
})
->schema(function (array $arguments) {
if (isset($arguments['item'])) {
if ($arguments['item']['is_protected']) {
return [
TextInput::make('password')
->password()
->revealable()
->required()
->maxLength(255),
];
} else {
return null;
}
}
})
->action(function (array $arguments, array $data) {
if (isset($arguments['item'])) {
if ($arguments['item']['is_protected']) {
if ($arguments['item']['password'] != $data['password']) {
Notification::make()
->title('Password is incorrect')
->danger()
->send();
return;
} else {
session()->put('folder_password', $data['password']);
}
}
if (! $arguments['item']['model_type']) {
if (filament()->getTenant()) {
return redirect()->to(url(filament()->getCurrentPanel()->getId() . '/' . filament()->getTenant()->id . '/media?folder_id=' . $arguments['item']['id']));
} else {
return redirect()->route('filament.' . filament()->getCurrentPanel()->getId() . '.resources.media.index', ['folder_id' => $arguments['item']['id']]);
}
}
if (! $arguments['item']['model_id'] && ! $arguments['item']['collection']) {
if (filament()->getTenant()) {
return redirect()->to(url(filament()->getCurrentPanel()->getId() . '/' . filament()->getTenant()->id . '/folders?model_type=' . $arguments['item']['model_type']));
} else {
return redirect()->route('filament.' . filament()->getCurrentPanel()->getId() . '.resources.folders.index', ['model_type' => $arguments['item']['model_type']]);
}
} elseif (! $arguments['item']['model_id']) {
if (filament()->getTenant()) {
return redirect()->to(url(filament()->getCurrentPanel()->getId() . '/' . filament()->getTenant()->id . '/folders?model_type=' . $arguments['item']['model_type'] . '&collection=' . $arguments['item']['collection']));
} else {
return redirect()->route('filament.' . filament()->getCurrentPanel()->getId() . '.resources.folders.index', ['model_type' => $arguments['item']['model_type'], 'collection' => $arguments['item']['collection']]);
}
} else {
if (filament()->getTenant()) {
return redirect()->to(url(filament()->getCurrentPanel()->getId() . '/' . filament()->getTenant()->id . '/media?folder_id=' . $arguments['item']['id']));
} else {
return redirect()->route('filament.' . filament()->getCurrentPanel()->getId() . '.resources.media.index', ['folder_id' => $arguments['item']['id']]);
}
}
}
});
}
public function render(): mixed
{
return view('filament-media-manager::livewire.folder-component');
}
}
</file>
<file path="tests/database/factories/FolderFactory.php">
<?php
namespace TomatoPHP\FilamentMediaManager\Tests\Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use TomatoPHP\FilamentMediaManager\Models\Folder;
class FolderFactory extends Factory
{
protected $model = Folder::class;
public function definition(): array
{
$name = $this->faker->words(2, true);
return [
'name' => $name,
'collection' => Str::slug($name),