【发布时间】:2019-11-30 13:56:57
【问题描述】:
我正在从数据库中获取数据,并且我有一个字段 profile_pic,我正在将图像名称保存在我的数据库中,我的响应如下所示:
"basicInfo": {
"id": 205,
"first_name": "new name",
"middle_name": "middle",
"profile_pic": "3q4Vs8iHdY.png",
}
如您所见,profile_pic 我正在获取图像名称和存储图像的文件夹 public/profile_images,当我点击获取 Api 时,我得到了 profile_pic 中图像名称的响应。 但我想通过附加来自 public/profile_images 的路径来获得我的回复的完整路径:
我收到此响应的代码
$userBasicInfo = $this->userBasicInfo->where('user_id', $user_id)->first();
这会获取所有数据,但我也想在我的 profile_pic 中附加图像路径名 我怎么能这样做? 我被困在这里了
class UserBasicInfo extends Model
{
use SoftDeletes;
const DELETED_AT = 'deletedAt';
protected $table = "user_basic_info";
protected $fillable = [
'first_name','city','state','zip','social_security','middle_name', 'last_name', 'profile_pic', 'date_of_birth', 'gender', 'area_id', 'user_id', 'created_by', 'updated_by', 'created_at', 'deletedAt','title','cell_no','address','work_phone','fax','extension','primary_facility','affiliated_facility','employed_by','emergency_phone','designation','department','employment_type','biography','hiring_date','from','to'
];
protected $hidden = ['deletedAt'];
function user() {
return $this->belongsTo('App\User', 'id', 'user_id');
}
public function getFromAttribute($value){
$createdAt= Carbon::parse($value);
return $createdAt->toIso8601String();
}
public function getToAttribute($value){
$createdAt= Carbon::parse($value);
return $createdAt->toIso8601String();
}
}
if (!empty($userBasicInfo->profile_pic)){
$deleteImage =$userBasicInfo->profile_pic;
unlink(public_path('profile_images').'/'.$deleteImage);
}
【问题讨论】: