Handle empty or missing icon

This commit is contained in:
Bubka 2020-01-08 17:03:41 +01:00
parent 8ed572bb24
commit 0e79209b6d
4 changed files with 23 additions and 4 deletions

View File

@ -3,6 +3,7 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
class TwoFAccount extends Model
{
@ -16,4 +17,22 @@ class TwoFAccount extends Model
* @var string
*/
protected $table = 'twofaccounts';
/**
* Null empty icon resource has gone
*
* @param string $value
* @return string
*/
public function getIconAttribute($value)
{
if( !Storage::exists('public/' . pathinfo($value)['basename']) ) {
return '';
}
return $value;
}
}

View File

@ -1,6 +1,6 @@
<template>
<div>
<figure class="image is-64x64" style="display: inline-block">
<figure class="image is-64x64" style="display: inline-block" v-if="icon">
<img :src="icon">
</figure>
<p class="is-size-4 has-text-grey-light">{{ service }}</p>

View File

@ -4,7 +4,7 @@
<div class="buttons are-large is-centered">
<span v-for="account in accounts" class="button is-black twofaccount" >
<span @click.stop="getAccount(account.id)">
<img :src="account.icon">
<img :src="account.icon" v-if="account.icon">
{{ account.service }}
<span class="is-family-primary is-size-7 has-text-grey">{{ account.account }}</span>
</span>

View File

@ -28,8 +28,8 @@
<span class="file-label">Choose an image</span>
</span>
</label>
<span class="tag is-black is-large" v-if="twofaccount.icon.length > 0">
<img class="icon-preview" :src="twofaccount.icon" >
<span class="tag is-black is-large" v-if="twofaccount.icon">
<img class="icon-preview" :src="'../' + twofaccount.icon" >
<button class="delete is-small" @click="deleteIcon"></button>
</span>
</div>