UniSharp/laravel-fileapi

Get url from view

wielski opened this issue · 3 comments

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' }}

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.

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.

Hello @wielski ,
We suggest you use FileApi like below :
2015-12-29 10 57 22

Create your helper function in your User model, dealing with FileApi and default image.
So in blade you can just use the code below :

{{ $user->avatarImage() }}

And you will get exactly what you want.
Hope this helps you.