PHPackages                             diegoalvarezb/laravel-service-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. diegoalvarezb/laravel-service-utils

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

diegoalvarezb/laravel-service-utils
===================================

Utils for internal Laravel services.

v1.0.1(8y ago)19MITPHPPHP &gt;=5.6

Since Sep 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/diegoalvarezb/laravel-service-utils)[ Packagist](https://packagist.org/packages/diegoalvarezb/laravel-service-utils)[ Docs](https://github.com/diegoalvarezb/laravel-service-utils)[ RSS](/packages/diegoalvarezb-laravel-service-utils/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (3)Used By (0)

laravel-service-utils
=====================

[](#laravel-service-utils)

This tool adds some utilities for internal services in [Laravel](https://laravel.com/).

Using this package, you could extend all your services (classes with the application business logic) from `Diegoalvarezb\ServiceUtils\AbstractService` and use some funcionalities:

- Service response interface
- Log management

### Requirements

[](#requirements)

- PHP &gt;= 5.6
- Laravel &gt;= 5.0

### Installation and configuration

[](#installation-and-configuration)

Package installation with composer:

```
composer require diegoalvarezb/laravel-service-utils

```

And add the service provider in your `config/app.php` file:

```
Diegoalvarezb\FrontMessages\ServiceUtilsServiceProvider::class
```

And this command will add the service-utils config file to the laravel config folder:

```
php artisan vendor:publish --tag=service-utils
```

### Service response interface

[](#service-response-interface)

Use the next command to return the result of a method:

```
return $this->generateResponse($data = [], $errorCode = 'NO_ERROR', $message = '');
```

The first param contains an array with all data. The second one must be the error code (this one must exists in the service-utils config file). The third one an additional message (if you don't send this param, the corresponding in the config file will be selected).

This method will return a `ServiceResponse` object, wich has the next methods:

- hasErrors()
- isCritical()
- getMessage()
- getData()
- getHttpCode()

### Service log management

[](#service-log-management)

Use the next command to write info the log file:

```
$this->logException($exception, $type = 'error', $customMessage = '');
```

The first param contains the exception. The second one must be the log type. The third one an additional message.

The list of log types:

- error
- emergency
- alert
- critical
- warning
- notice
- info

The structure of the log: \[datetime\] local.LOG\_TYPE: Path\\To\\Class | method() | (Exception) | message

### Example config file: service-utils.php

[](#example-config-file-service-utilsphp)

```
