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.
In this step, we'll install laravel 11 application using the following command.
composer create-project laravel/laravel example-app
Now, we'll install the laravel laravolt/avtar composer package using the following command.
composer require laravolt/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>
Now, run the laravel 11 application using the following command.
php artisan serve
You might also like:
Hello friends, in this tutorial, we will see jQuery show and hide effects example. jQuery show method and jQuery...
Jan-21-2022
In this article, we will see Laravel 9 whereIn / whereNotIn / orWhereIn / orWhereNotIn Query Example. The whereIn()...
Oct-17-2022
Today we will learn next previous link button pagination in laravel, Using paginate method you can easily create paginat...
Jun-14-2021
In this article, we will see laravel 9 QR code generator example. As per the current trend, many websites and appli...
Mar-25-2022