How to create word document file in Laravel?
This article will provide you how to create work document file in laravel. in this post, i want to share with you simple example of how to generate word file in laravel. you just need to follow few step to creating word file in laravel.
In todays world, we sometimes require to create word document for export some data. For example if you have some important data like terms and conditions then it's always want to pdf or word that way we can get in better formate, So in laravel you can do it using phpoffice/phpword composer package.
In this example, i will give you very simple example to generate docx file. Here i installed phpoffice/phpword package and then i simply create one route, then in controller method i add simple text and one image. So you can basically understand how it works.
So let's see bellow steps.
Step 1: Install Phpword Package
Here, in first step we will install phpoffice/phpword package, this package is not specially for laravel but it is for php, but anyway we can use normally, So let's simple run bellow command and install it:
composer require phpoffice/phpword
Step 2: Add Route
After installed successfully phpword package, we will add new route for demo to generate docx file, So let's add one route for demo.
Route::get('generate-docx', '[email protected]');
Step 3: Add Controller Method
In last step, we will add generateDocx() method in HomeController. So i give you whole code of my controller, let's copy and paste bellow code:
I hope it can help you...