I am getting data from database and i have a field profile_pic and i am saving image name in my database my response looks like:
"basicInfo": {
"id": 205,
"first_name": "new name",
"middle_name": "middle",
"profile_pic": "3q4Vs8iHdY.png",
}
As you can see profile_pic i am getting image name and there folder public/profile_images where my images is storing and when i hit get Api I GOT following response with image name in profile_pic. but i want to get full path in my response by attaching path from public/profile_images:
My code where I got this response
$userBasicInfo = $this->userBasicInfo->where('user_id', $user_id)->first();
This gets all data but i want to attach image path name in my profile_pic as well How I can do that? I am stuck here
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);
}