<commit_before># Laravel 5 Model Transformers

This package helps API developers to easily transform Eloquent models into arrays that are convertible to JSON.

Here's how you use it, let's say you have a model with the following data:

```json
{
	"name": "iPhone",
	"type": 1
}
```
Here you use a numerical value to represent the different types, you also have a mutator in the model that maps the numerical value to a string.

Inside the controller we can transform the model to be represented into more API friendly structure. 

```php
<?php
class SomeController{
	function getIndex(){
		$product = Product::find(1);
		
		return response([
			"product" => ProductTransformer::transform($product)
		]);
	}
}
```

The above code will result a JSON string that may look like this:

```json
{
	"product": {
		"name": "iPhone",
		"type": {
			"key": 1,
			"name": "Mobile Phone"
		}
	}
}
```

---

## Installation
Begin by installing the package through Composer. Run the following command in your terminal:

```
composer require themsaid/laravel-model-transformers:dev-master
```

Once composer is done, add the package service provider in the providers array in `config/app.php`

```
Themsaid\Transformers\TransformersServiceProvider::class
```

Finally publish the config file:

```
php artisan vendor:publish
```

That's all what's needed.

## Usage
Create a model transformer class by extending the AbstractTransformer class:

```php
<?php
class CategoryTransformer extends Themsaid\Transformers\AbstractTransformer
{
    public function transformModel(Model $item)
    {
        $output = [
            'name'		=> $item->name,
            'type'		=> [
            		'key'	=> $item->type,
            		'name'	=> $item->typeName
            ],
        ];
<commit_msg>   update readme<commit_after># Laravel 5 Model Transformers

This package helps API developers to easily transform Eloquent models into arrays that are convertible to JSON.

Here's how you use it, let's say you have a model with the following data:

```json
{
	"name": "iPhone",
	"type": 1
}
```
Here you use a numerical value to represent the different types, you also have a mutator in the model that maps the numerical value to a string.

Inside the controller we can transform the model to be represented into more API friendly structure. 

```php
<?php
class SomeController{
	function getIndex(){
		$product = Product::find(1);
		
		return response([
			"product" => ProductTransformer::transform($product)
		]);
	}
}
```

The above code will result a JSON string that may look like this:

```json
{
	"product": {
		"name": "iPhone",
		"type": {
			"key": 1,
			"name": "Mobile Phone"
		}
	}
}
```

---

## Installation
Begin by installing the package through Composer. Run the following command in your terminal:

```
composer require themsaid/laravel-model-transformers:dev-master
```

Once composer is done, add the package service provider in the providers array in `config/app.php`

```
Themsaid\Transformers\TransformersServiceProvider::class
```

Finally publish the config file:

```
php artisan vendor:publish
```

That's all what we need.

## Usage
Create a model transformer class by extending the AbstractTransformer class:

```php
<?php
class CategoryTransformer extends Themsaid\Transformers\AbstractTransformer
{
    public function transformModel(Model $item)
    {
        $output = [
            'name'		=> $item->name,
            'type'		=> [
            		'key'	=> $item->type,
            		'name'	=> $item->typeName
            ],
        ];

{'fraction_non_alphanumeric': 0.10819209039548022, 'fraction_numerical': 0.0022598870056497176, 'mean_word_length': 3.505089058524173, 'pattern_counts': {'":': 14, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2158454', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1003, 'n_words': 393}