如何解决我正在使用Spatie Media libray,我生成img,但是这些图像未显示在视图中
我的模型结构:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\HasMedia\Interfaces\HasMediaConversions;
class Profile extends Model implements HasMedia
{
use InteractsWithMedia;
protected $fillable = ['user_id','avatar','first_name','last_name','about','job_title','company','phone','country','state','city','industry','sub_industry','linkedin','website','youtube','facebook','instagram','twitter','membership','pending'];
public function getAvatarAttribute()
{
return $this->getMedia('images')->last();
}
}
我的视图结构
<img src="{{$user->avatar->getUrl()}}" alt="" class="d-block ui-w-100 rounded-circle">
我的控制器代码
$profile = Profile::create([
'avatar' => $file,]);
$profile->addMedia($request->image)
->preservingOriginal()
->toMediaCollection('images');
我在file-system.php中的路径
'media' => [
'driver' => 'local','root' => storage_path('app/public/profile'),'url' => env('APP_URL').'/storage/app/public/profile','visibility' => 'public',],
目录结构是
storage/app/public/profile
“在查看网址中”是这样生成的
<img src="http://localhost:8000/storage/app/public/profile/34/multiple_mailer.png"
路径非常正确,但我的图片未加载 它也已添加到数据库中
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。