MalBe's avatar
Level 4

Livewire Profile Background Image

Hello All, Pretty new to Livewire, Jetstream and Laravel

After installing a Laravel 8 Project with Jetstream and Livewire after registering a user and logging in under the user/profile section you can update the profile image, storing the path in the user table profile_photo_path

I've added a field in the user table using migration for profile_background_path what is the simplest way to add a second image upload to add the path to this field?

I've tried replicating the code in views/update-profile-information-form.php (photo) and changing the variables to profile_background that failed.

I tried following an online tut on adding image to database using php artisan livewire:make profile-background-form and putting it in it's on database linking it with user_id and adding

      <div class="mt-10 sm:mt-0">
            @livewire('profile-background-form')
        </div> 

in profile/show.blade.php, I managed to get the form to place the image in the storage livewire_tmp folder, but couldn't for the life on me to insert it in to the database??

In frustration I have deleted the files with php artisan livewire:delete command and jumped on here to see if anyone could help me achieve what I want to do....

Any help appreciated in advance.

Mal

0 likes
2 replies
drehimself's avatar

I think you're going to have some familiarity with Livewire to accomplish this.

If you're still fairly new to Laravel in general, I would recommend first trying this on a brand new project. Just have a basic form with a button that allows you to upload a file. Setup all the database fields as needed.

Once you have that working, move onto Livewire. There's an entire series here on Laracasts with an episode dedicated to file uploads: https://laracasts.com/series/livewire-basics/episodes/11.

Once you're familiar with Livewire, you should be able to integrate it into Jetstream.

You can also see how Jetstream implements it in these files:

/vendor/laravel/jetstream/stubs/livewire/resources/views/profile/update-profile-information-form.blade.php

and

/vendor/laravel/jetstream/src/Http/Livewire/UpdateProfileInformationForm.php

Good luck!

MalBe's avatar
Level 4

Hi @drehimself,

Thanks for the response, is it my understanding, the when you make the 2 livewire files

app/Http/Livewire/ProfileBackground.php is the Controller resources/views/profile-background.blade.php is the view to render

the I just add use App\Models\User to ProfileBackground.php to get it to add to the database?

then in the form it should be wire:model="user"

or am I completely wrong??

I would like to get it all working using Livewire

Please or to participate in this conversation.