У меня проблемы с отображением загруженных изображений из базы данных.
Вот что я получаю:
[{"id": 4, "model_type": "App \ Asset", "model_id": 16, "collection_name": "фото", "имя": "5d83621e459eb_le15", "имя_файла": "5d83621e459eb_le15.jpg", "mime_type": "изображение / JPEG", "диск": "общественность", "размер": 40804, "манипуляции": [], "custom_properties": {"генерируемые_конверсии": {"большой палец": true}}, "responseive_images": [], "order_column": 4, "creation_at": "2019-09-19 11:11:05"," updated_at ":" 2019-09-19 11:11:06 "}]
view.blade.php
<div class="panel-body">
<div>
<h2>{{ $asset->name }}</h2>
<span class="label label-info label-many"> {{ $asset->category->name ?? '' }} </span>
<div> {{ $asset->photos }} </div>
<br>
<p>{{ $asset->description }}</p>
<h5><strong>{{ trans('cruds.asset.fields.date') }}</strong></h5>
<p> {{ $asset->date ?? '' }}</p>
<span class="label label-success label-many">{{ trans('cruds.asset.fields.location') }} : {{ $asset->location->name ?? '' }}</span>
<span class="label label-default label-many">{{ trans('cruds.asset.fields.budget') }} : {!! $asset->budget !!}</span>
<span class="label label-warning label-many">{{ trans('cruds.asset.fields.nbAssociers') }} : {!! $asset->nbAssociers !!}</span>
<br>
<br>
<strong>{{ trans('cruds.asset.fields.assigned_to') }} : </strong>
<p>{{ $asset->assigned_to->name ?? '' }}</p>
<br>
<a style="margin-top:20px;" class="btn btn-default" href="{{ url()->previous() }}">
{{ trans('global.back_to_list') }}
</a>
</div>
</div>
Модель
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\Models\Media;
use Laravel\Scout\Searchable;
class Asset extends Model implements HasMedia
{
use SoftDeletes, HasMediaTrait;
use Searchable;
public $table = 'assets';
protected $appends = [
'photos',
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
protected $fillable = [
'name',
'description',
'status_id',
'created_at',
'updated_at',
'deleted_at',
'category_id',
'location_id',
'date',
'budget',
'nbAssociers',
'assigned_to_id',
];
public static function boot()
{
parent::boot();
Asset::observe(new \App\Observers\AssetsHistoryObserver);
}
public function registerMediaConversions(Media $media = null)
{
$this->addMediaConversion('thumb')->width(50)->height(50);
}
public function assetsHistories()
{
return $this->hasMany(AssetsHistory::class, 'asset_id', 'id');
}
public function category()
{
return $this->belongsTo(AssetCategory::class, 'category_id');
}
public function getphotosAttribute()
{
return $this->getMedia('photos');
}
public function status()
{
return $this->belongsTo(AssetStatus::class, 'status_id');
}
public function location()
{
return $this->belongsTo(AssetLocation::class, 'location_id');
}
public function assigned_to()
{
return $this->belongsTo(User::class, 'assigned_to_id');
}
И я использую в своем контроллере:
use MediaUploadingTrait;