---
title: "Immutable Value Objects in PHP and Laravel With the Bags Package"
url: https://daily.dev/posts/immutable-value-objects-in-php-and-laravel-with-the-bags-package-4fdn5qbsd
source_url: https://laravel-news.com/immutable-value-objects-in-php-and-laravel
type: article
source: "Laravel News"
published: 2025-01-08T14:12:42.872Z
updated: 2026-03-15T05:32:07.400Z
tags: ["general-programming", "laravel", "php"]
reading_time: 2
upvotes: 24
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Immutable Value Objects in PHP and Laravel With the Bags Package

**[Laravel News](https://daily.dev/sources/ln)** · 2 min read · 24 upvotes · 0 comments

## Summary

The Bags package in PHP and Laravel helps create immutable value objects, providing type safety, data casts, and built-in validation. It can replace regular arrays in your code to enhance data encapsulation. The package integrates with Laravel's Collection and Validation features and supports Eloquent casts and injecting validated Bag objects into controllers. Key features include immutability, strong typing, value casting, collection support, and composability. The package also includes an Artisan command to generate Bags.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://laravel-news.com/immutable-value-objects-in-php-and-laravel>

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 0 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#laravel](https://daily.dev/tags/laravel), [#php](https://daily.dev/tags/php)

[View this post on daily.dev](https://daily.dev/posts/immutable-value-objects-in-php-and-laravel-with-the-bags-package-4fdn5qbsd)
