PHP code example of horcrux / handleresponse

1. Go to this page and download the library: Download horcrux/handleresponse 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/ */

    

horcrux / handleresponse example snippets




return [
    'withstatus' => false,
    'default_dirver' => 'default',
    'drivers' => [
        'drivers_name' => [
            'status_key' => 'status',
            'reset_success' => ['data'],
            'reset_error' => ['number', 'message']
        ]
    ]
];



return [
    'withstatus' => false,
    'default_dirver' => 'profile-api',
    'drivers' => [
        'profile-api' => [
            'status_key' => 'status',
            'reset_success' => [ 'api_number','data'],
            'reset_error' => ['error_number', 'error_message']
        ]
    ]
];



namespace App\Http\Controllers;

use Horcrux\Handleresponse\Core\Traits\LaravelResponse;
use Illuminate\Http\Request;

class TestController extends Controller
{
    use LaravelResponse;
    public function index()
    {
        return $this->senddata([152 , 'one']);
    }
}

return $this->senderror([258 , 'user is not found'])

return $this->senderror([258 , 'user is not found'],500);
// response will return with 500 status code

return $this->senderror([258 , 'user is not found'],500 , 'other_driver');

$this->change_driver('other_driver');
return $this->senderror([258 , 'user is not found']);

return $this->sendsuccess();



return [
    'withstatus' => false,
    'default_dirver' => 'profile-api',
    'drivers' => [
        'profile-api' => [
            'status_key' => 'status',
            'reset_success' => ['api_number', 'data'],
            'reset_error' => ['error_number', 'error_message'],
            'h_profile' => ['profile_id', 'profil_name', 'data'],
        ]
    ]
];
 


namespace App\Http\Controllers;

use Horcrux\Handleresponse\Core\Traits\LaravelResponse;

class TestController extends Controller
{
    //
    use LaravelResponse;
    public function index()
    {
        return $this->h_profile([252, 'youssef', [
            'one' => 'one',
            'two' => 'two'
        ]]);
        //return $this->h_profile([data_array], status_code, driver_name)
    }
}
bash
php artisan vendor:publish --provider="Horcrux\Handleresponse\HandleresponseServiceProvider" --tag="config"