【问题标题】:Why does the image name change between Mysql and Laravel为什么 Mysql 和 Laravel 之间的镜像名称会发生​​变化
【发布时间】:2021-10-11 17:52:21
【问题描述】:

我有一个问题,即 Mysql post featured 字段中的图像名称是:“/uploads/posts/img1.jpg”。但是当我从 Laravel 检索图像名称时,使用以下内容陈述: $image_path = $post->featured ,我得到一个完整的网址 "http://127.0.0.1:8000/uploads/posts/img1.jpg" 。 我需要将结果采用数据库格式才能删除图像。

请帮忙。

【问题讨论】:

  • 能否提供 Post.php 文件?
  • public function getFeaturedAttribute($featured)更新为public function getFeaturedAttribute()
  • 我在 Post.php 中有以下函数: public function getFeaturedAttribute($featured){ return asset($featured);你有什么建议?
  • 替换 asset($featured);,by asset($this->featured);

标签: php mysql laravel


【解决方案1】:

当你回显 $image_path 时,你得到了什么?

如果你使用asset($image_path),它会放完整的URL。

如果只想获取路径,使用{{ $image_path }}或者直接{{ $post->featured }}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 2018-05-05
    • 2012-10-11
    • 2015-02-13
    • 2022-01-16
    相关资源
    最近更新 更多