fix: use absolute URL for logo in all mail templates
The logo ``src`` was ``/storage/photos/shares/logo.png`` — a relative path to a file that doesn't exist. Email clients cannot resolve relative URLs. Replaces with the absolute URL to the actual logo at ``https://boutique.jardinenvie.com/img/logo.png`` across all 4 mail templates.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private $oldSrc = '/storage/photos/shares/logo.png';
|
||||
|
||||
private $newSrc = 'https://boutique.jardinenvie.com/img/logo.png';
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$this->replaceLogoInAllTemplates($this->oldSrc, $this->newSrc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$this->replaceLogoInAllTemplates($this->newSrc, $this->oldSrc);
|
||||
}
|
||||
|
||||
private function replaceLogoInAllTemplates(string $from, string $to): void
|
||||
{
|
||||
$templates = DB::table('mail_templates')->get();
|
||||
|
||||
foreach ($templates as $template) {
|
||||
$translations = json_decode($template->html_template, true);
|
||||
|
||||
if (! $translations) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$changed = false;
|
||||
|
||||
foreach ($translations as $lang => $html) {
|
||||
$updated = str_replace($from, $to, $html);
|
||||
if ($updated !== $html) {
|
||||
$translations[$lang] = $updated;
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($changed) {
|
||||
DB::table('mail_templates')
|
||||
->where('id', $template->id)
|
||||
->update(['html_template' => json_encode($translations, JSON_UNESCAPED_UNICODE)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user