class User extends Illuminate\Database\Eloquent\Model { protected static function boot() { parent::boot(); static::creating(function ($user) { $user->created_by = Auth::id(); }); } }
class User extends Illuminate\Database\Eloquent\Model { protected static function boot() { parent::boot(); static::addGlobalScope('notDeleted', function ($query) { $query->whereNull('deleted_at'); }); } }In this example, the `notDeleted` global scope adds a constraint to queries on the `User` model that excludes any records with a non-null `deleted_at` field. The `Illuminate\Database\Eloquent` package provides an object-relational mapper (ORM) for the Laravel framework. The `boot` method is part of this package's model class and is used to customize the behavior of individual model instances.