kickthemooon's avatar

updating img src via ajax

@freekmurze I am using dropzone and also spatie media library.

My html looks like this:

<div class="profileavatar">
                <img src="{{ $thumbprofileimg }}" class="img-responsive">
                @if($thumbprofileimg != '/front/img/userimage.png')
                <div class="removebutton">
                    <a href="/user/{{ $user->slug }}/avatar/delete" class="btn btn-danger" role="button">Remove avatar</a>
                </div>
                @endif
            </div>

            <form action="/user/{{ $user->slug }}/avatar" class="dropzone" id="my-awesome-dropzone">
                {!! csrf_field() !!}
                <div class="dz-message">Drag your avatar here</div>
            </form>

so I have:

<img src="{{ $thumbprofileimg }}" class="img-responsive">

which is retrieved in the user controller edit method:

$thumbprofileimg = $user->getMedia('avatars')->first()->getUrl('medium');

when i drop something to dropzone it is directed to this method:

public function avatarUpload(Request $request, $slug)
    {
        $user = User::findBySlug($slug);

        $user->clearMediaCollection('avatars');

        $user->addMedia($request->file('file'))->toCollectionOnDisk('avatars', 'avatars');

        return 'Working on it';
    }



So How could I retrieve this:

{{ $thumbprofileimg }}

via ajax after dropzone uploads a new image?

0 likes
0 replies

Please or to participate in this conversation.