$user = new User; $user->unguard(); $user->name = 'John Doe'; $user->email = 'john.doe@example.com'; $user->save();
class User extends Model { public static function createNew($data) { $user = new User; $user->unguard(); $user->fill($data); $user->save(); return $user; } }This example shows how to use `unguard()` inside a static method to create a new `User` model instance from an associative array of data. The `fill()` method is used to set the properties on the model, which can be any keys from the `$fillable` property or any keys not listed in the `$guarded` property. Package library: This code example belongs to Laravel Eloquent ORM, which is a part of the Laravel framework.