Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@ class User extends \LaravelBook\Ardent\Ardent {
public $autoHydrateEntityFromInput = true;
}
```
####Using $autoHydrateEntityFromInput on model "update"

Even if `$autoHydrateEntityFromInput` is already set to `true`, it will not work if you are updating a record.

To solve this problem, below is an example on how to change the `username` field of the Users table.

Using plain Laravel model:

```php
$user = User::find(1);
$user->username = Input::get('username');
$user->save();
```

Using model extended with Ardent:

```php
$user = User::find(1);
$user->forceEntityHydrationFromInput = true; // add this line to force hydration
$user->save();
```

If we are going to view our Users table, the `username` with `id` equal to `1` will be updated with the value of `Input::get('username')`. Try to set `$user->forceEntityHydrationFromInput` to false and you will see that no updates will happen.

The `Ardent->forceEntityHydrationFromInput` can also be set in your model class:

```php
class User extends \LaravelBook\Ardent\Ardent {
public $autoHydrateEntityFromInput = true;
public $forceEntityHydrationFromInput = true;
}
```

<a name="modelhooks"></a>
## Model Hooks (since [2.0](https://github.com/laravelbook/ardent/tree/v2.0.0))
Expand Down