To use the data variable it must be a associative array 'CustomerName'=>'John Doe' so you would build it similar in most cases like when you build the validation $data variable.
So then you can use $CustomerName directly in your view.
test route from a project where i used dom-pdf
Route::get('pdf/po/{id}',function($currentBidId){
/*
* pass data through to invoice view
*/
$invoiceData = \AcceptedAuctionBid::where('transaction_code','=',$currentBidId)
->with('withBid','belongsToSeller','belongsToBidder','belongsToBidWithAnimal')
->first();
$invoiceInfo = [
'invoice_number'=>$invoiceData->transaction_code,
'bid_amount'=>$invoiceData->withBid->bid_amount,
'timestamp'=>$invoiceData->withBid->created_at,
//sellers details
'sellers_company'=>$invoiceData->belongsToSeller->businessInformation->company_name,
'sellers_email'=>$invoiceData->belongsToSeller->businessInformation->email,
'sellers_tel'=>$invoiceData->belongsToSeller->businessInformation->tel,
'sellers_vat_nr'=>$invoiceData->belongsToSeller->businessInformation->vat_nr,
'sellers_address'=>explode(',',$invoiceData->belongsToSeller->businessInformation->address),
];
//end data
$invoice = PDF::loadView('pdf.purchaseorder',$invoiceInfo);
return $invoice->stream();
});
then in my view I can use the keys as variables directly.