themsaid / laravel-model-transformer Goto Github PK
View Code? Open in Web Editor NEWEasy transformation layer for complex model attributes.
License: MIT License
Easy transformation layer for complex model attributes.
License: MIT License
* @param Model $model
* @return array
*/
public function transformModel(Model $model): array
{
return [
];
}
:array
Return type declaration is available in PHP 7 only
but composer.json "require" "php" : ">=5.3.0"
Hello,
I have problem in using the model transformer, on the controller I called it using this line
$appointments = Appointment::where('field', condition)->get(); return Response()->json(['appointments' => AppointmentTransformer::transform( $appointments )], 200);
and my model transformer is
`
class AppointmentTransformer extends Themsaid\Transformers\AbstractTransformer{
public function transformModel(Model $item)
{
$output = [
"field_key" => value
];
return $output;
}
}
and I get below error:
Declaration of AppointmentTransformer::transformModel() should be compatible with Themsaid\Transformers\AbstractTransformer::transformModel(Illuminate\Database\Eloquent\Model $modelOrCollection). Is there any way how can I fixt this? Thanks :)
Hi,
I found your package very simple but yet very useful, I tried to install it on Laravel 5.3 version but it seems it has an error. Is there any version that would support Laravel 5.3?
Thanks,
Noel
FYI for anyone upgrading to L5.5 with this package in use:
In Laravel 5.5, a helper method named transform was added to the framework, thus overwriting LMT's helper method of the same name.
Fixes for you:
I know the consumer API is not really the "Laravel way", but wouldn't it be better to work on a Laravel integration of the Symfony Serializer rather than re-inventing the wheel? Actually the serializer offer you a couple more features:
I had a bit of trouble to use for my app to be honest, mainly because Eloquent models are a bit special making them hard to automatically serialize. I eventually got over it by using EloquentSerializer though.
WDYT?
Hey, nice package, but the transformer works only with a model or collection. What about paginated results?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.