Get url from view
wielski opened this issue · 3 comments
wielski commented
I have assigned alias for FileApi class in app.php
'File' => Unisharp\FileApi\FileApi::class,
When I try to use it in blade view i got error
Non-static method Unisharp\FileApi\FileApi::get() should not be called statically, assuming $this from incompatible context (View: /Users/wielski/Documents/MAMP/shop.dev/resources/views/admin/users/list.blade.php)
Please make static function for using in Blade, like
{{ File::get($user->avatar, 'S') or '/images/avatars/default.png' }}
wielski commented
I have to write custom function in helpers.php
use \Unisharp\FileApi\FileApi;
function getFile($name, $size = 'L', $path = 'images/', $cloud = false){
$fa = new FileApi($path);
if($fa->getUrl($name, $size) == $path) return false;
return $fa->get($name, $size);
}
Using like this:
{{ (getFile($user->avatar, 'S', 'images/avatars/')) ? getFile($user->avatar, 'S', 'images/avatars/') : 'images/avatars/default.png' }}
Very poor solution, but it working.
getUrl always return only path, if file not found.
And, local storage path is olways without / (images/avatar/file.png instead /images/avatar/file.php)
It's not good to.
FreedomKnight commented
Hi, @wielski
we don't use alias because we want to let it change image path more flexible.
so we let developer setting path at initial time.
We will consider your opinion.
