https://github.com/appstract/laravel-response-macros
Extra response macro's for Laravel
https://github.com/appstract/laravel-response-macros
laravel macros php response
Last synced: about 1 year ago
JSON representation
Extra response macro's for Laravel
- Host: GitHub
- URL: https://github.com/appstract/laravel-response-macros
- Owner: appstract
- License: mit
- Created: 2017-07-04T09:25:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-22T15:07:25.000Z (over 8 years ago)
- Last Synced: 2024-11-03T22:48:31.237Z (over 1 year ago)
- Topics: laravel, macros, php, response
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 33
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Response Macros
[](https://packagist.org/packages/appstract/laravel-response-macros)
[](https://packagist.org/packages/appstract/laravel-response-macros)
[](LICENSE.md)
[](https://travis-ci.org/appstract/laravel-response-macros)
This package is a collection of custom response macros that you can re-use in a variety of your routes and controllers.
## Installation
You can install the package via composer:
``` bash
composer require appstract/laravel-response-macros
```
## Usage
### Message
``` php
return response()->message('hello world!', 200);
```
Result
``` json
{
"message": "hello world!"
}
```
With the Http `Status Code: 200`
### Error
``` php
return response()->error('Something went wrong', $statuscode = 400);
```
Result
``` json
{
"message": "Something went wrong"
}
```
With the Http `Status Code: 400`
### Success
``` php
return response()->success(['some' => 'data'], $statuscode = 200);
```
Result
``` json
{
"data": {"some": "data"}
}
```
With the Http `Status Code: 200`
### PDF
Creates a (downloadable) PDF response from PDF contents.
``` php
return response()->pdf($pdfData, 'filename.pdf', $download = false);
```
## Testing
``` bash
$ composer test
```
## Contributing
Contributions are welcome, [thanks to y'all](https://github.com/appstract/laravel-blade-directives/graphs/contributors) :)
## About Appstract
Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on [Medium](https://medium.com/appstract). You can [follow us on Twitter](https://twitter.com/teamappstract), [buy us a beer](https://www.paypal.me/teamappstract/10) or [support us on Patreon](https://www.patreon.com/appstract).
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.