weward/laramacro

A set of custom macros for Laravel

v10.0.1 2023-12-25 04:03 UTC

This package is auto-updated.

Last update: 2024-04-25 04:50:19 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A set of custom macros for Laravel

Table of Contents

Installation

You can install the package via composer:

# for the meantime
composer require weward/laramacro:dev-master 

Publish Service Provider

php artisan vendor:publish --tag=laramacro-providers

You may register the service srovider at config/app.php

'providers' => [

    // ...

    App\Providers\LaraMacroServiceProvider::class,
]

Usage

Response Macro

jsonApi()

A superset of ->json() response format that can accept Laravel Resource payload.

// Pass normal payload and http status
return response()->jsonApi($data, 200);

// Pass a Resource and hhtp status
return response()->jsonApi(new UserResource($data), 200);

Credits

License

The MIT License (MIT). Please see License File for more information.