Download the PHP package skraeda/laravel-automapper without Composer
On this page you can find all versions of the php package skraeda/laravel-automapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download skraeda/laravel-automapper
More information about skraeda/laravel-automapper
Files in skraeda/laravel-automapper
Package laravel-automapper
Short Description Laravel wrapper for automapper-plus by Mark Gerarts
License MIT
Informations about the package laravel-automapper
Laravel AutoMapper
This package integrates AutoMapper+ by Mark Gerarts into Laravel.
This documentation will assume you are familiar with how AutoMapper+
works.
Installation
Install via composer:
AutoMapping
For this example, we want to be able to easily map between Employee
and EmployeeDto
models.
Example models
Registering the mappings
We can register the mappings in our boot
method in any ServiceProvider
Mapping between the models
Using the facade or alias
Using the contract
Using the helper functions
Custom Mappers
AutoMapper+
allows us to define separate classes to perform the mapping if it requires more complicated logic or if we need better performance.
Let's change EmployeeDto
to look like this instead
To teach the AutoMapper+
how to use a custom mapper to map to the new EmployeeDto
model then delete the old mapping and create a new custom mapper.
You can manually register this custom mapping in your ServiceProvider
or you can use a mapping.php
config file.
Publish the config file
Register custom mappers
Starting with Version 2, you can have Custom Mappers automatically discovered by enabling directory scanning in the mapping.php
config file. Mappers found within the directories you specify in mapping.php
with the Maps
attribute will be automatically registered.
If you have multiple mappers discovered this way, you may want to turn on caching for your production environment within the mapping.php
config file. With caching enabled, the first request will scan your files for mappers and store them in a cache file (default: app_dir/storage/app/framework/automapper/automapper.php) that's loaded for the next requests.
You can use php artisan mapping:clear
to clear the mapping cache directory if you add new mappers.
You can also use php artisan mapping:cache
to immediately scan and cache the mappers.
Helpers and methods
Collection macro
You can use the autoMap
method on a collection to map into some target class.
Generator command
You can use the make:mapper
artisan command to generate the boilercode for a custom mapper.
AutoMapperContract
AutoMapperFacade
Helper functions
Testing
Run
Alternatively
Generate coverage
Alternatively
Run static analysis
Alternatively
Changelog
V2.0.0
- Add the
Maps
attribute - Adds several interfaces to scan and cache custom mappers discovered with the
Maps
attribute - Adds config options to enable scanning and caching
- Adds artisan commands
mapping:clear
andmapping:cache
to manage mapping cache - Adds method
registerCustomMapper
to \Skraeda\AutoMapper\Contracts\AutoMapperContract
v1.2.0
- Add Laravel 8 support
V1.1.0
All versions of laravel-automapper with dependencies
illuminate/support Version ~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/console Version ~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0
mark-gerarts/auto-mapper-plus Version v2.0.0-alpha1