Passing array to Blade::render for email template

I'm working on a custom email system with email template all works fine until the variables that i pass to Blade::render are strings but i need to sent an array this array is a results of a repeater field and is soterd in the db as json field this is the relevant part of my code

$accessories = $repair->accessories;

$variables = [
'repairId' => $repair->id,
'customerName' => $repair->customer->customer_name,
'item' => $repair->brand->name.' '.$repair->item->name.' '.$repair->item->model,
'serialNumber' => $repair->serialNumber,
'technicianName' => $repair->technician->name,
'customerNote' => $repair->customer_note,
'createdAt' => $repair->created_at,
'accessories' => $accessories,
'appName' => env('APP_NAME')
];
...
$compiledContent = Blade::render($bladeContent, $variables);

$accessories = $repair->accessories;

$variables = [
'repairId' => $repair->id,
'customerName' => $repair->customer->customer_name,
'item' => $repair->brand->name.' '.$repair->item->name.' '.$repair->item->model,
'serialNumber' => $repair->serialNumber,
'technicianName' => $repair->technician->name,
'customerNote' => $repair->customer_note,
'createdAt' => $repair->created_at,
'accessories' => $accessories,
'appName' => env('APP_NAME')
];
...
$compiledContent = Blade::render($bladeContent, $variables);
the error is htmlspecialchars(): Argument #1 ($string) must be of type string, array given without the accessories, works fine
1 Reply
awcodes
awcodes12mo ago
The output in your blade file is probably wrong {{ $accessories }} for work with an array. You need to loop it.
Want results from more Discord servers?
Add your server