PHP code example of karunais13 / api-response-formatter

1. Go to this page and download the library: Download karunais13/api-response-formatter 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/ */

    

karunais13 / api-response-formatter example snippets


	...
	
	'providers' => array(
		...
		Karu\ApiResponse\ApiResponseProvider::class,
	],
	
	...

        'aliases' => [
            ...
            ApiResponse: Karu\ApiResponse\Facades\ApiResponseFacade::class
        ]



return [
    'message' => [
        0           => '',

        // Sample Code setup
        // Model    : User
        100         => 'User not found.',
        101         => 'Incorrect combination of login information.',
        102         => 'You\'re not allow to use the same current password.',
        103         => 'Failed to update new password.',
        104         => 'This email is not available.',
        105         => 'Failed to create new user account.',
        106         => 'Failed to upload avatar.',
        107         => 'Failed to update user account.',
        108         => 'Invalid image file format.',
        109         => sprintf('Image file size cannot larger than %dMB.', 5),
        110         => 'Old password incorrect.',
        111         => 'Email does not exits. Please contact admin to reset the password.',
        112         => 'Password successfully updated',
        113         => 'User FB ID already exists',
        114         => 'Too many login attempt',
        115         => 'Failed to update new token.',
    ],
];
    

    ....
    use ApiResponse;
    
    function example(){
        ....
        ....
        ....

        return ApiResponse::res(true, 100, []);
    }



ApiResponse::res(true, 100, [])



ApiResponse::resCustom(true, "User not found", [])


	...

        'aliases' => [
            ...
            {user alias name}: Karu\ApiResponse\Facades\ApiResponseFacade::class
        ]

	...

        'aliases' => [
            ...
            NpRes: Karu\ApiResponse\Facades\ApiResponseFacade::class
        ]

 php artisan vendor:publish --provider='Karu\ApiResponse\ApiResponseProvider'