PHP code example of ptdot / errormessage

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

    

ptdot / errormessage example snippets


'providers' => [
    Ptdot\ErrorMessage\ErrorMessageServiceProvider::class,
],

'aliases' => [
    'ErrorMessage' => Ptdot\ErrorMessage\ErrorMessage::class,
]



// default usage using facade
try {
    throw new \Exception('This is exception message');
} catch (\Exception $exception) {
    return response()->json([
        'errors' => ErrorMessage::displayExceptionMessage($exception)
    ], 500);
}

// you may need traceAsString option enabled using this way:
return response()->json([
        'errors' => ErrorMessage::traceAsString()->displayExceptionMessage($exception)
    ], 500);

// Need to override exception message? Don't worry
return response()->json([
        'errors' => ErrorMessage::displayExceptionMessage($exception, 'exception message will be overrided with this')
    ], 500);
bash
php artisan vendor:publish