How to Generate Avatar Image for User in Laravel 11

Websolutionstuff | Jan-16-2025 | Categories : Laravel

Creating avatar images for users in Laravel 11 can enhance the visual appeal of your application and make it more personalized. Whether it’s generating random avatars, initials-based images, or custom user-profile pictures, Laravel makes it easy to implement this feature.

In this guide, I’ll walk you through how to generate avatar images for users in Laravel 11 step by step, using simple and beginner-friendly methods.

How to Generate Avatar Image for Users in Laravel 11

How to Generate Avatar Image for User in Laravel 11

 

Step 1: Install Laravel 11 Application

In this step, we'll install laravel 11 application using the following command.

composer create-project laravel/laravel example-app

 

Step 2: Install laravolt/avatar

Now, we'll install the laravel laravolt/avtar composer package using the following command.

composer require laravolt/avatar

 

Step 3: Setup Avatar

Next, we'll create a custom avatar using the following command.

Avatar::create('Websolutionstuff')->toSvg();

resources/views/users/index.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>How to Generate Avatar Image for User in Laravel 11</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div class="container">
    <div class="card mt-5">
        <div class="card-header"><h4>User List</h4></div>
        <div class="card-body" id="table-data">            
            <table class="table table-striped table-bordered">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Email</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($users as $user)
                    <tr>
                        <td>{{ $user->id }}</td>
                        <td>{!! Avatar::create($user->name)->setDimension(35, 35)->setFontSize(15)->toSvg() !!} {{ $user->name }}</td>
                        <td>{{ $user->email }}</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>

            {{ $users->links("pagination::bootstrap-5") }}

        </div>
    </div>
</div>

</body>
</html>

 

Step 4: Run the Laravel 11 Application

Now, run the laravel 11 application using the following command.

php artisan serve

 


You might also like:

Recommended Post
Featured Post
jQuery Show and Hide Effects Example
jQuery Show and Hide Effects E...

Hello friends, in this tutorial, we will see jQuery show and hide effects example. jQuery show method and jQuery...

Read More

Jan-21-2022

Laravel 9 whereIn / whereNotIn / orWhereIn / orWhereNotIn
Laravel 9 whereIn / whereNotIn...

In this article, we will see Laravel 9 whereIn / whereNotIn / orWhereIn / orWhereNotIn Query Example. The whereIn()...

Read More

Oct-17-2022

Next Previous Link Button Pagination in Laravel
Next Previous Link Button Pagi...

Today we will learn next previous link button pagination in laravel, Using paginate method you can easily create paginat...

Read More

Jun-14-2021

Laravel 9 QR Code Generator Example
Laravel 9 QR Code Generator Ex...

In this article, we will see laravel 9 QR code generator example. As per the current trend, many websites and appli...

Read More

Mar-25-2022