Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wesleywillians's avatar

Hydrators in Laravel 5

Hi Folks,

For me is very common to use Hydrators in ZF 2 and SF 2, to hydrate and extract data from my entities.

How do you do that in Laravel? Is there any class to do anything similar?

All the best

0 likes
4 replies
impbob36's avatar

There are 2 sets of class, depending on what your targeting.

Models:

Use: fill(array $attributes) or forceFill(array $attributes)

"Fill the model with an array of attributes." / "Force mass assignment"

$data = ['id' => 1, 'comment' => 'My comment'];
...
$model = new Comment;
$model->fill($data);

Collections:

Use: hydrate(array $items, string|null $connection = null) / hydrateRaw(string $query, array $bindings = array(), string|null $connection = null)

I haven't use this one yet so not really sure on it's use.

*taken from http://laravel.com/api/5.0/Illuminate/Database/Eloquent/Model.html#method_fill

4 likes

Please or to participate in this conversation.