PHP code example of ambengers / eloquent-word

1. Go to this page and download the library: Download ambengers/eloquent-word library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ambengers / eloquent-word example snippets


@php
// You automatically have access to $word within your view template,
// which is an instance of \PhpOffice\PhpWord\PhpWord::class...
$section = $word->addSection();

$section->addTitle($title);

$section->addTextBreak();

$section->addText($body);
@endphp
 php
namespace App\Word;

use Ambengers\EloquentWord\AbstractEloquentWord;

class PostWord extends AbstractEloquentWord
{
    public function getData() : array
    {
        return [
            'title' => $this->model->title,
            'body'  => $this->model->body,
        ];
    }

    public function getView() : string
    {
        return 'posts.word';
    }
}
 php
return app(PostWord::class)
    ->model($post)
    ->handle();
 php
return app(PostWord::class)
    ->model($post)
    ->toMediaCollection('reports')
    ->handle();