PHP code example of youngmayor / app-response

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

    

youngmayor / app-response example snippets


'providers' => [
    // ...
    YoungMayor\AppResponse\AppResponseServiceProvider,
    // ...
],

'aliases' => [
    // ...
    "AppResponse": "YoungMayor\AppResponse\Facade\AppResponse"
    // ...
],
 
// ...
use YoungMayor\AppResponse\API; 
// ...

class SampleController extends Controller
{
    public function sampleMethod(API $api)
    {
        // ...
        return $api->success("Action was successful");
    }
}
 
// ...
use YoungMayor\AppResponse\Web; 
// ...

class SampleController extends Controller
{
    public function sampleMethod(Web $web)
    {
        // ...
        return $web->success("Action was successful");
    }
}
 
// ...
use YoungMayor\AppResponse\Auto; 
// ...

class SampleController extends Controller
{
    public function sampleMethod(Auto $auto)
    {
        // ...
        return $auto->success("Action was successful");
    }
}
 
// ...
use YoungMayor\AppResponse\Facade\AppResponse; 
// or 
use AppReponse; // this utilises the Facade aliase
// ...

class SampleController extends Controller
{
    public function sampleMethod()
    {
        // ... 
        return AppResponse::success("Action was successful"); 
    }
}
 
class SampleController extends Controller
{
    public function sampleMethod()
    {
        // ...
        return appResponse()->success("Action was successful"); // for automatic response
        // or 
        return appResponse()->api->success("Action was successful"); // for API only resppnse
        // or 
        return appResponse()->web->success("Action was successful"); // for Web only resppnse
    }
}
sh
php artisan vendor:publish --provider="YoungMayor\AppResponse\AppResponseServiceProvider"