Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joshuaf's avatar

Spark prepending URL to images

Whenever I upload an image, spark is prepending the entire base URL to the photo_url parameter. I don't see an option to prevent this in the config/app or anywhere else.

I just want to be able to set the photo_url to my desired text.

0 likes
3 replies
Cronix's avatar

You'd have to swap the UpdateProfilePhoto@handle method.

Put this in the booted() method of SparkServiceProvider

Spark::swap('UpdateProfilePhoto@handle', function ($user, $data) {
    $file = $data['photo'];

    $path = $file->hashName('profiles');

    // We will store the profile photos on the "public" disk, which is a convention
    // for where to place assets we want to be publicly accessible. Then, we can
    // grab the URL for the image to store with this user in the database row.
    $disk = Storage::disk('public');

    $disk->put(
        $path, $this->formatImage($file)
    );

    $oldPhotoUrl = $user->photo_url;
        
    $user->forceFill([
        'photo_url' => $disk->url($path),
    ])->save();

    if (preg_match('/profiles\/(.*)$/', $oldPhotoUrl, $matches)) {
        $disk->delete('profiles/'.$matches[1]);
    }
});

I just copied the original method into it above. You'd just adjust it how you need it.

joshuaf's avatar

I kinda already thought about that and I got so frustrated that I bypassed that function altogether and wrote my own code to upload and store the image. Yet there is still some snippet of code somewhere that injects that path.

joshuaf's avatar

So, I eventually realized that the code may be prepending the URL because I was settign the photo_url variable to a relative path /Profile/image.jpg. When I set it to the full address, nothing was prepended.

Please or to participate in this conversation.