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

Commit f68fa59

Browse files
Update README.md
1 parent 0f265f1 commit f68fa59

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 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 that have 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,40 @@ Install the package using composer:
1822
composer require michael-rubel/laravel-model-mapper
1923
```
2024

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

0 commit comments

Comments
 (0)