Adding file repository method to get all files w/o folders

parent dc98714c
......@@ -172,4 +172,16 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
{
return $this->model->where('folder_id', $folderId)->get();
}
public function findForVirtualPath(string $path)
{
$prefix = config('asgard.media.config.files-path');
return $this->model->where('path', $prefix . $path)->first();
}
public function allForGrid(): Collection
{
return $this->model->where('is_folder', 0)->get();
}
}
......@@ -44,4 +44,8 @@ interface FileRepository extends BaseRepository
* @return Collection
*/
public function allChildrenOf(int $folderId) : Collection;
public function findForVirtualPath(string $path);
public function allForGrid() : Collection;
}
......@@ -246,6 +246,17 @@ class EloquentFileRepositoryTest extends MediaTestCase
$this->assertEquals($nestedFolder->id, $file->folder_id);
}
/** @test */
public function it_can_fetch_all_files_only()
{
$folderRepository = app(FolderRepository::class);
$folderRepository->create(['name' => 'My Folder', 'parent_id' => 0]);
$this->createFile();
$this->createFile();
$this->assertCount(2, $this->file->allForGrid());
}
private function createFile($fileName = 'random/name.jpg')
{
return File::create([
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment