mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 10:24:36 -04:00
Added generateUrl method for getting assets (#3258)
* Added generateUrl method for getting assets * Fix return types
This commit is contained in:
parent
45cc67075d
commit
69fa60b91c
32
app/Helpers/GenerateUrl.php
Normal file
32
app/Helpers/GenerateUrl.php
Normal 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;
|
||||||
|
}
|
@ -47,5 +47,10 @@ class UploadFileTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertNotNull($document);
|
$this->assertNotNull($document);
|
||||||
|
|
||||||
|
print_r([
|
||||||
|
'relative' => generateUrl($document),
|
||||||
|
'full' => generateUrl($document, true)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user