Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit d6cd04a

Browse files
committed
Merge branch 'main' of github.com:michael-rubel/laravel-model-mapper
2 parents 4befbf8 + 791d0c7 commit d6cd04a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![Laravel Model Mapper](https://user-images.githubusercontent.com/37669560/147101154-e70d8648-ffa3-48c6-b9a8-6a072b7c1f00.png)
2+
13
# Laravel Model-Property Mapper
24
[![Latest Version on Packagist](https://img.shields.io/packagist/v/michael-rubel/laravel-model-mapper.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-model-mapper)
35
[![Total Downloads](https://img.shields.io/packagist/dt/michael-rubel/laravel-model-mapper.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/michael-rubel/laravel-model-mapper)
@@ -6,6 +8,8 @@
68
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/michael-rubel/laravel-model-mapper/run-tests/main?style=flat-square&label=tests&logo=github)](https://github.com/michael-rubel/laravel-model-mapper/actions)
79
[![PHPStan](https://img.shields.io/github/workflow/status/michael-rubel/laravel-model-mapper/phpstan/main?style=flat-square&label=larastan&logo=laravel)](https://github.com/michael-rubel/laravel-model-mapper/actions)
810

11+
This package provides functionality to map your model attributes to local class properties with the same names.
12+
913
The package requires PHP `^8.x` and Laravel `^8.67`.
1014

1115
[![PHP Version](https://img.shields.io/badge/php-^8.x-777BB4?style=flat-square&logo=php)](https://php.net)
@@ -18,6 +22,43 @@ Install the package using composer:
1822
composer require michael-rubel/laravel-model-mapper
1923
```
2024

25+
## Usage
26+
```php
27+
use WithModelMapping;
28+
```
29+
30+
Then in constructor or any other method:
31+
```php
32+
$this->mapModelAttributes($model);
33+
```
34+
35+
This is especially handy with Livewire components when you want to map your model data to the view.
36+
37+
For example:
38+
```php
39+
class CompanyProfile extends Component
40+
{
41+
use WithModelMapping;
42+
43+
/**
44+
* Frontend properties.
45+
*
46+
* @var string|null
47+
*/
48+
public ?string $name;
49+
public ?string $tax_number;
50+
public ?string $address;
51+
52+
/**
53+
* @return void
54+
*/
55+
public function mount(Company $company): void
56+
{
57+
$this->mapModelAttributes($company);
58+
}
59+
}
60+
```
61+
2162
## Testing
2263
```bash
2364
composer test

0 commit comments

Comments
 (0)