Roadirsh Roadirsh - 26 days ago 7
PHP Question

File::exists return false for existing file in email job queued

I'm trying to send an email using the Laravel's queue, in this email, I'm showing the profile picture of an user if the file exist using this function:

public function getProfilePictureAttribute()
{
$path = 'users/' . $this->id . '/picture.png';
if (File::exists(public_path() . $path)) {
return $path;
} else {
return $this->picture_default;
}
}


I use the same function on the web and it's working, but in the email, so via artisan and the table job, I always get the default picture.
I can't figure this out.

Fky Fky
Answer

Problem solved by :

public function getProfilePictureAttribute()
{
    $path = 'users/' . $this->id . '/picture.png';
    if (File::exists(realpath(public_path() . $path))) {
        return $path;
    } else {
        return $this->picture_default;
    }
}
Comments