Skip to content

Commit 82c714c

Browse files
Geidel Guerrafrasmage
Geidel Guerra
authored andcommitted
Fix Media::scopeForPathOnDisk not working when directory name is empty. (#39)
1 parent b1c286f commit 82c714c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Media.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function scopeWhereBasename(Builder $q, $basename)
116116
public function scopeForPathOnDisk(Builder $q, $disk, $path)
117117
{
118118
$q->where('disk', $disk)
119-
->where('directory', pathinfo($path, PATHINFO_DIRNAME))
119+
->where('directory', File::cleanDirname($path))
120120
->where('filename', pathinfo($path, PATHINFO_FILENAME))
121121
->where('extension', pathinfo($path, PATHINFO_EXTENSION));
122122
}

tests/integration/MediaTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ public function test_it_can_be_queried_by_path_on_disk()
8282
$this->assertEquals(4, Media::forPathOnDisk('tmp', 'foo/bar/baz/bat.jpg')->first()->id);
8383
}
8484

85+
public function test_it_can_be_queried_by_path_on_disk_when_directory_is_empty()
86+
{
87+
factory(Media::class)->create([
88+
'id' => 4,
89+
'disk' => 'tmp',
90+
'directory' => '',
91+
'filename' => 'bat',
92+
'extension' => 'jpg'
93+
]);
94+
$this->assertEquals(4, Media::forPathOnDisk('tmp', 'bat.jpg')->first()->id);
95+
}
96+
8597
public function test_it_can_view_human_readable_file_size()
8698
{
8799
$media = factory(Media::class)->make(['size' => 0]);

0 commit comments

Comments
 (0)