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

Raitik's avatar

Laravel Livewire - Show success message after file upload

Hi,

i am using livewire for my authentication and uploading files.

For while it's uploading i am simply using this from the documentation:

<div wire:loading wire:target="profile_image">Uploading...</div>

And it does get the job done but there isn't provided for when it's done uploading, like a success message, how do i do that?

0 likes
2 replies
DeonO's avatar

When WithFileUploads has completed the upload, it emits an upload:finished event. You can listen for that and then show a message.

/**
 * Listens for the upload:finished event and calls the uploadDocument method.
 */
public $listeners = [
    'upload:finished' => 'uploadDocument',
];

/**
 * Validates the uploaded document and displays a success message.
 *
 * @param  string  $documentModel  The name of the document model.
 * @return void
 */
public function uploadDocument($documentModel)
{
    // Validate the uploaded document
    $this->validate([
        $documentModel => 'required|mimes:pdf,jpg,jpeg,png|max:1024',
    ],[
        $documentModel.'.required' => 'The document is required',
        $documentModel.'.mimes'    => 'The document format must be either .pdf, .jpg, .jpeg or .png',
    ]);

    // Display a success message
    // TODO: Replace this with your own code to display the success message in the view
}
1 like
jtgraham38's avatar

You could also set a message variable in the component, like this:


class PhotoUpload extends Component
{
    use WithFileUploads;
	...
	public $notification = "";	
    ...
    public function uploadFiles()
    {
			... (handle upload here)
            
            //show a success message
            $this->notification = "Files uploaded successfully!";
            
        }
    }
    ...
}

Then just show $notification in your blade template:

<span>{{$notification}}</span>

Please or to participate in this conversation.