|
| 1 | + |
| 2 | +<p align="center"><img src="https://static.typeset.sh/images/typeset.sh-logo.svg" width="300"></p> |
| 3 | + |
| 4 | + |
1 | 5 | # Typeset.sh wrapper for laravel 7 |
2 | 6 |
|
| 7 | +This is a laravel 7 typeset.sh wrapper that lets you easily configure and use typeset.sh |
| 8 | +in your laravel project. |
| 9 | + |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +Make sure you have access to a valid composer token from typeset.sh. |
| 14 | + |
| 15 | +Add typeset.sh packages repository to composer. |
| 16 | + |
| 17 | + composer config repositories.typesetsh composer https://packages.typeset.sh |
| 18 | + composer require typesetsh/laravel-wrapper |
| 19 | + |
| 20 | + |
| 21 | +Then add the following line to register provider in `config/app.php` |
| 22 | +```php |
| 23 | +'providers' => [ |
| 24 | + |
| 25 | + // ... |
| 26 | + |
| 27 | + App\Providers\AppServiceProvider::class, |
| 28 | + App\Providers\AuthServiceProvider::class, |
| 29 | + App\Providers\EventServiceProvider::class, |
| 30 | + App\Providers\RouteServiceProvider::class, |
| 31 | +[+] Typesetsh\LaravelWrapper\ServiceProvider::class, |
| 32 | + |
| 33 | +], |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +The wrapper works similar to the view. Technically it wraps the view and uses its html output |
| 40 | +and renders it as pdf. |
| 41 | + |
| 42 | +### Facade |
| 43 | + |
| 44 | +You can use the facade pattern. Similar as you would render a view. |
| 45 | + |
| 46 | +```php |
| 47 | +use Typesetsh\LaravelWrapper\Facades\Pdf; |
| 48 | + |
| 49 | +Route::get('/invoice/print', function () { |
| 50 | + $invoice = new stdClass(); |
| 51 | + |
| 52 | + return Pdf::make('invoice', ['invoice' => $invoice]); |
| 53 | +}); |
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | +### Helper |
| 58 | + |
| 59 | +Alternative you can use the helper. |
| 60 | + |
| 61 | +```php |
| 62 | +use Typesetsh\LaravelWrapper\Facades\Pdf; |
| 63 | + |
| 64 | +Route::get('/invoice/print', function () { |
| 65 | + $invoice = new stdClass(); |
| 66 | + |
| 67 | + return typesetsh\pdf('invoice', ['invoice' => $invoice]); |
| 68 | +}); |
| 69 | +``` |
| 70 | + |
| 71 | +or force a download |
| 72 | + |
| 73 | +```php |
| 74 | +use Typesetsh\LaravelWrapper\Facades\Pdf; |
| 75 | + |
| 76 | +Route::get('/invoice/print', function () { |
| 77 | + $invoice = new stdClass(); |
| 78 | + |
| 79 | + return typesetsh\pdf('invoice', ['invoice' => $invoice])->forceDownload('invoice.pdf'); |
| 80 | +}); |
| 81 | +``` |
| 82 | + |
| 83 | + |
| 84 | +## Configuration |
| 85 | + |
| 86 | +Typeset.sh does not require much configuration. The only important aspect to understand is that |
| 87 | +by default typeset.sh does not allow including any external resources (image, css, fonts,...) |
| 88 | +unless specified. |
| 89 | + |
| 90 | +See the configuration file `config/typesetsh.php` for more information. By default, typeset.sh |
| 91 | +has access to the public directory and any http(s) resources. |
| 92 | + |
| 93 | +You can also publish the file using: |
| 94 | + |
| 95 | + php artisan vendor:publish --provider="Typesetsh\LaravelWrapper\ServiceProvider" |
| 96 | + |
| 97 | + |
| 98 | +## License |
| 99 | + |
| 100 | +This extension is under the [MIT license](LICENSE). |
| 101 | + |
| 102 | +However, it requires a version of [typeset.sh](https://typeset.sh/) to work. |
0 commit comments