PHP code example of vandarpay / service-repository

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

    

vandarpay / service-repository example snippets


class TestException extends ServiceException
{
    public const NEW_ERROR = 'new_error';

    public function configureExceptions()
    {
        $this->addException(self::NEW_ERROR, Response::HTTP_BAD_REQUEST, 'this is a test exception');
    }
}

$this->app->bind(UserRepository::class, UserService::class);

$this->app->singleton(UserRepository::class, UserService::class);

    if ($e instanceof ServiceException && ($request->wantsJson() || $request->is('api/*'))) {
        return response()->json(['code' => $e->getAppCode(), 'message' => $e->getMessage()], $e->getCode());
    }