NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// blade code for email template


<body>

<div class="email-container">

<div class="header">

{{-- If sponsor logo exists show it --}}
@if($logo)
<img src="{{ asset('storage/' . $logo ?? 'N/A') }}" alt="Sponsor Logo">
@else
<h1>Welcome!</h1>
@endif

</div>

<div class="content">

<p>Hello <strong>{{ $user->name }}</strong>,</p>

<p>Your account has been created as a <strong>{{ ucfirst(str_replace('_',' ', $roleType)) }}</strong>.</p>

<p>You can now log in using the credentials below:</p>

<p>
<strong>Login Email:</strong> {{ $user->email }} <br>
<strong>Temporary Password:</strong> {{ $password }}
</p>

<a href="{{ url('/login') }}" class="btn">Login Now</a>

<p style="margin-top:20px;">
For security purposes, you will be required to set a new password upon your first login.
</p>

<p>If you have any questions, please feel free to contact support.</p>

<p>Thanks,<br>Nutriservice</p>
</div>

<div class="footer">
&copy; {{ date('Y') }} Nutriservice. All rights reserved.
</div>

</div>

</body>

// UserService code to create new user and send email based on role

public function createUser(array $data, string $role): User
{
$tempPassword = Str::random(10);

if ($role === 'sponsor') {
$uniqueCode = User::generateSponsorAccountNumber();
} elseif ($role === 'sponsor-staff') {
$sponsor = User::findOrFail($data['sponsor_id']);
$uniqueCode = User::generateSponsorStaffCode($sponsor);
} elseif ($role === 'center') {
$sponsor = User::findOrFail($data['sponsor_id']);
$uniqueCode = User::generateCenterUniqueCode($sponsor);
}

$user = User::create([
'name' => $data['name'] ?? $data['first_name'] . ' ' . $data['last_name'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'phone' => $data['phone'],
'role_type' => $role,
'unique_code' => $uniqueCode,
'status' => $data['status'] ?? 'active',
'is_active' => $data['is_active'] ?? true,
'password' => Hash::make($tempPassword),
'must_change_password' => true,
'sponsor_id' => $data['sponsor_id'] ?? null,
'center_id' => $data['center_id'] ?? null,
'created_by' => auth()->id(),
]);

$user->assignRole($role);
$this->sendWelcomeMailByRole($user, $tempPassword);

return $user;
}

/**
* Decide which mail logic applies based on role
*/
protected function sendWelcomeMailByRole(User $user, string $password): void
{
$roleType = match ($user->role_type) {
'sponsor' => 'sponsor',
'sponsor-staff' => 'sponsor-staff',
'center' => 'center',
'center-staff' => 'center-staff',
'parent' => 'parent',
default => 'user',
};

$this->mailService->sendUserWelcomeMail(
$user,
$password,
$roleType
);
}

// Below is how i am storing logo while creating a sponsor
// SponsorService

public function createSponsor(array $data)
{
return DB::transaction(function () use ($data) {

/** 1️⃣ Create user */
$user = $this->userService->createUser($data, 'sponsor');

/** 2️⃣ Handle logo upload (IF EXISTS) */
$logoPath = null;

if (!empty($data['logo']) && $data['logo']->isValid()) {
$logoPath = $data['logo']->store('sponsor_logos', 'public');
}

/** 3️⃣ Create sponsor details */
SponsorDetail::create([
'user_id' => $user->id,
'description' => $data['description'] ?? null,
'website_url' => $data['website_url'] ?? null,
'country' => $data['country'] ?? null,
'address_line1' => $data['address_line1'] ?? null,
'address_line2' => $data['address_line2'] ?? null,
'city' => $data['city'] ?? null,
'state' => $data['state'] ?? null,
'zip_code' => $data['zip_code'] ?? null,
'logo' => $logoPath,
]);

return $user;
});
}


// SponsorController

public function store(Request $request)
{
$request->merge([
'is_active' => $request->has('is_active')
]);

$validated = $request->validate([
'name' => 'required|string|max:100',
'first_name' => 'required|string|max:100',
'last_name' => 'nullable|string|max:100',
'email' => 'required|email|unique:users,email',
'phone' => 'required|string|max:30',
'description' => 'nullable|string|max:2000',
'website_url' => 'required|url|max:255',
'address_line1' => 'nullable|string|max:255',
'address_line2' => 'nullable|string|max:255',
'city' => 'nullable|string|max:100',
'state' => 'nullable|string|max:100',
'zip_code' => 'nullable|string|max:30',
'status' => ['nullable', Rule::in(['new', 'active', 'inactive'])],
'logo' => 'nullable|image|max:2048',
]);

try {

$user = $this->sponsorService->createSponsor([
...$validated,
'logo' => $request->file('logo'), //
'is_active' => $request->boolean('is_active'),
]);

return response()->json([
'success' => true,
'message' => config('messages.sponsor_created'),
'user' => $user,
]);
} catch (Throwable $e) {
Log::error('Sponsor creation failed', [
'error' => $e->getMessage()
]);

return response()->json([
'success' => false,
'message' => config('messages.sponsor_creation_error'),
], 500);
}
}


"When a sponsor-staff or center is created then mail is sent to the particular role, then sponsor logo (the sponsor for what particular sponsor-staff or center is created) is not displaying on the top of email template. Please implement the functionality to show the sponsor logo in sponsor-staff and center email"
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.