Added generateUrl method for getting assets (#3258)

* Added generateUrl method for getting assets

* Fix return types
This commit is contained in:
Benjamin Beganović 2020-01-29 03:31:34 +01:00 committed by GitHub
parent 45cc67075d
commit 69fa60b91c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,32 @@
<?php
use App\Models\Document;
use Illuminate\Support\Facades\Storage;
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
/**
* Generate url for the asset.
*
* @param Document $document
* @param boolean $absolute
* @return string|null
*/
function generateUrl(Document $document, $absolute = false)
{
$url = Storage::disk($document->disk)->url($document->path);
if($url && $absolute) return url($url);
if ($url) return $url;
return null;
}

View File

@ -47,5 +47,10 @@ class UploadFileTest extends TestCase
);
$this->assertNotNull($document);
print_r([
'relative' => generateUrl($document),
'full' => generateUrl($document, true)
]);
}
}