2 Simple Ways to Generate User Avatar in Laravel

2 Simple Ways to Generate User Avatar in Laravel

Laravel Daily

1 год назад

11,686 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Anthony Cirinelli
Anthony Cirinelli - 22.01.2023 04:27

This is very helpful. I have been generating these avatars on the fly with this package as a user trait. Seems like it would be much smarter to store them.

Ответить
Lê Đình Hữu Tài
Lê Đình Hữu Tài - 26.10.2022 12:48

great tip, thank you🥰

Ответить
Pitch
Pitch - 24.10.2022 23:07

Hello. Could you please make a video about laravel precognition?

Ответить
Opu Hasnat
Opu Hasnat - 24.10.2022 17:32

Hey Man, I want to know something about the multiple insertion. On a form submit, if user click couple of time on the submit button it will insert the same form data multiple times. We can project that by using JS on the button but what we I can do on MySQL end? I hope you got my problem. Let me know if you need more explanation.

Ответить
Rick C
Rick C - 24.10.2022 16:22

If you don't need extra shapes and colors, this is a couple of lines of PHP to generate initial based avatars. I use it on one of my client projects, mind you I only use first letter of the name but it isn't a lot harder to get two (it gets a bit tricky with people with last names that are two or more words separated by spaces of course). {{substr($thread->user->name,0,1)}}

Ответить
Mwatha Kinyua
Mwatha Kinyua - 24.10.2022 15:04

I prefer Gravatar.

Ответить
Laravel Tree
Laravel Tree - 24.10.2022 14:41

Sir Your Work is awesome But One Problem in your video cannot under stand code perfectly.

Ответить
Bernard Onigbinde
Bernard Onigbinde - 24.10.2022 14:22

For anyone considering @Mel's way:

Create a component, say: UserAvatar.vue
<div class="rounded-full m-1 h-16 w-16 relative justify-center uppercase bg-gray-200 flex items-center text-2xl font-semibold" v-text="name.split(' ').slice(0, 2).join(' ').split(' ').map((n) => n[0]).join('')" />

<script setup>
let props = defineProps({
name: String
})
</script>

You can pass more customizations as props I guess: bg-color, font size, avatar size
*Inline styles are from tailwind

Ответить
Douglas Lindner
Douglas Lindner - 24.10.2022 13:55

I enjoy your daily videos...thank you. Regarding avatars, why bother with these dependencies? It's so easy to create avatars with just a little CSS that it doesn't seem worth it to me to add extra dependencies to a project. I used to use Laravolt and removed it two years ago...no need, in my view. I won't comment about external services. That's just not a great idea for this purpose.

Ответить
will you
will you - 24.10.2022 11:25

I was wondering if you plan to release a course for laravel docker integration, from scratch and also with Sail? And also, do you plan to cover microservices in your future courses? Ps. Love your work, you have influenced me and my dev career like no other.

Ответить
Dev
Dev - 24.10.2022 10:28

i display a default blank avatar image when there is a newly created user w/o avatar.

Ответить
Ammar Ali
Ammar Ali - 24.10.2022 10:27

Second one is good.

Thank you. 👍

Ответить
Marvellous Ifezue
Marvellous Ifezue - 24.10.2022 10:24

Me being the crazy individual I am

You can either upload a profile picture
Or upload one to gravatar or
Initials

Ответить
specky fahad
specky fahad - 24.10.2022 09:54

I'll go with the second one.

Ответить
Al Nahian
Al Nahian - 24.10.2022 08:43

I'd prefer the second one. But if there was no options available, I'd go for the exact same way @Mel mentioned.

Ответить
Mel
Mel - 24.10.2022 08:24

I prefer trimming the name and get the initials using javascript then lay it out in a circle div could be much lighter. But nice to know these packages! As always, awesome work!

Ответить
Marcelo Lima
Marcelo Lima - 24.10.2022 08:04

Nice

Ответить
Marcelo Lima
Marcelo Lima - 24.10.2022 08:01

Cheguei primeiro. 😉

Ответить