ItSolutionStuff.com

Generate word document file in php Laravel 5 Example

By Hardik Savani • May 14, 2024
PHP Laravel

In this example, i will explain how to create docs file using php laravel 5. i will show you simply way to generate docx file in laravel 5.8. you can easily create create word document file in laravel 5. we will generate *.doc file without using any composer package.

we will generate doc file from html content in laravel 5 application.

We might be some time require to create docs file from database in laravel. if you need to same requirement then you can easily achieve to generate word document.

We will use headers with html content and file name will be *.docx. we can use simple html tag like p, strong, ul, li etc. that all tags will support for creating docs file. you can follow this tutorial to create simple way docs file.

Create Route:

Route::get('generate-docs', function(){

$headers = array(

"Content-type"=>"text/html",

"Content-Disposition"=>"attachment;Filename=myfile.doc"

);

$content = '<html>

<head><meta charset="utf-8"></head>

<body>

<p>My Content</p>

<ul><li>Cat</li><li>Cat</li></ul>

</body>

</html>';

return \Response::make($content,200, $headers);

});

You can try and check it.

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Vue JS MultiSelect Dropdown Example

Read Now →

Guzzle http client request tutorial with Laravel 5.8

Read Now →

Build Admin Panel with Laravel 5.8

Read Now →

Jquery Ajax Form Validation with Laravel 5.8

Read Now →

Build RESTful API In Laravel 5.8 Example

Read Now →

Laravel 5.8 CRUD (Create Read Update Delete) Tutorial For Beginners

Read Now →

Laravel One to One Eloquent Relationship Tutorial

Read Now →

Laravel Create Word Document File using phpoffice/phpword package

Read Now →