File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -40,10 +40,20 @@ public function directories()
40
40
}
41
41
42
42
$ this ->folders = Cache::remember ($ this ->key (), $ this ->ttl (), function () {
43
- return $ this ->query ()->select (['folder ' ])
44
- ->distinct ()
45
- ->get ()
46
- ->map (fn ($ model ) => ['path ' => $ model ->folder , 'type ' => 'dir ' ]);
43
+ return
44
+ collect (
45
+ $ this ->query ()->select (['folder ' ])
46
+ ->distinct ()
47
+ ->get ()
48
+ ->map (fn ($ model ) => ['path ' => $ model ->folder , 'type ' => 'dir ' ])
49
+ )
50
+ ->merge (
51
+ collect ($ this ->container ->disk ()->getFolders ('/ ' , true )
52
+ ->filter (fn ($ folder ) => ! Str::startsWith ($ folder , '. ' ))
53
+ )
54
+ ->map (fn ($ folder ) => ['path ' => $ folder , 'type ' => 'dir ' ])
55
+ )
56
+ ->unique ();
47
57
});
48
58
49
59
return $ this ->folders ;
Original file line number Diff line number Diff line change 3
3
namespace Tests \Assets ;
4
4
5
5
use Illuminate \Http \UploadedFile ;
6
+ use Illuminate \Support \Facades \Cache ;
7
+ use Illuminate \Support \Facades \Storage ;
6
8
use PHPUnit \Framework \Attributes \Test ;
7
9
use Statamic \Facades \AssetContainer ;
10
+ use Statamic \Facades \Blink ;
8
11
use Statamic \Testing \Concerns \PreventsSavingStacheItemsToDisk ;
9
12
use Tests \TestCase ;
10
13
@@ -98,4 +101,20 @@ public function it_doesnt_nest_folders_that_start_with_the_same_name()
98
101
$ this ->assertCount (1 , $ filtered );
99
102
$ this ->assertSame ($ filtered ->keys ()->all (), ['one/two ' ]);
100
103
}
104
+
105
+ #[Test]
106
+ public function it_includes_empty_folders_in_the_directory_listing ()
107
+ {
108
+ $ container = tap (AssetContainer::make ('test ' )->disk ('test ' ))->save ();
109
+ $ container ->makeAsset ('one-two/file.txt ' )->upload (UploadedFile::fake ()->create ('one.txt ' ));
110
+
111
+ $ this ->assertCount (1 , $ container ->contents ()->directories ());
112
+
113
+ Cache::flush ();
114
+ Blink::flush ();
115
+
116
+ Storage::disk ('test ' )->makeDirectory ('another ' );
117
+
118
+ $ this ->assertCount (2 , $ container ->contents ()->directories ());
119
+ }
101
120
}
You can’t perform that action at this time.
0 commit comments