Save generated .doc file on specific path or send to mail in Laravel

160 Views Asked by At
public function wordExport($ticket_id)
{
    $icon=Ticket::findOrFail($ticket_id)->icon;
    $contact=Icon::findOrFail($icon->id)->contact;
    $ticket=Ticket::findOrFail($ticket_id);
    $wordFile=new TemplateProcessor('word/Notice of Intention to Appear.docx');
    $name=$contact->first_name." ".$contact->last_name;
    $wordFile->setValue('name',$name );
    $wordFile->setValue('address',$contact->address);
    $wordFile->setValue('province',$contact->province);
    $wordFile->setValue('postal_code',$contact->postal_code);
    $wordFile->setValue('ticket_no',$ticket->ticket_no);
    $wordFile->setValue('icon_code',$ticket->icon_code);
    $wordFile->setValue('date',$icon->date);
    $wordFile->setValue('email',$contact->email);
    $wordFile->setValue('city',$contact->city);
    $wordFile->setValue('phone',$contact->phone);
    $wordFile->setValue('currentDate', date("Y-m-d"));
    $wordFile->setImageValue('ticketimage',array('path' =>public_path().'/uploads/file/'.$ticket->images_name , 'width' => 600, 'height' => 900, 'ratio' => true));
    $wordFile->setValue('interpreter',$icon->interpreter);
    $fileName=$contact->first_name.date("mdY").time();
    $wordFile->saveAs($fileName.'.docx');

    return response()->download($fileName.'.docx')->deleteFileAfterSend(true);
}

This code generates Word file, but I want to save it at a specific path or send this file as an email attachment.

0

There are 0 best solutions below