Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Toml Laravel Package

internal/toml

PHP 8.1+ TOML 1.0.0/1.1.0 parser and encoder. Parse TOML strings/files into PHP arrays or an AST, modify documents, and serialize back to TOML with round-trip support.

View on GitHub
Deep Wiki
Context7

TOML v1.0.0 parser and encoder for PHP 8.1+

Frequently asked questions about Toml
How do I replace Laravel’s config.php arrays with TOML files using this package?
Use a custom config loader in a Laravel service provider to parse TOML files from the `config/` directory. Bind the loader to the `config.loader` key in the service container, then access TOML data via Laravel’s `config()` helper. For example, store `database.toml` in `config/` and access `config('database.host')` as usual.
Does this package support TOML 1.1 features like datetime formats or hex numbers?
Yes, this package fully supports TOML 1.1, including datetime formats, hex numbers, and bare keys. It outputs TOML 1.0-compatible strings by default for interoperability but parses 1.1 features correctly. Test with real-world TOML files (e.g., Kubernetes manifests) to ensure compatibility.
Can I use this package to generate Kubernetes ConfigMaps or Terraform templates from PHP arrays?
Absolutely. Use `Toml::encode()` to convert PHP arrays into TOML strings, then embed them in Kubernetes ConfigMaps or Terraform templates. For example, encode a PHP array to TOML and store it in a ConfigMap’s `data` field or use it as a Terraform local variable.
Will this package work with Laravel 9/10, or is it PHP 8.1+ only?
This package requires PHP 8.1+, which means it’s compatible with Laravel 9+ (LTS) and Laravel 10+. If you’re using an older Laravel version (e.g., 8.0), consider a polyfill like `php81-polyfill` or evaluate alternatives like `spatie/toml`, which supports older PHP versions.
How do I handle errors when parsing invalid TOML in a Laravel application?
The package throws exceptions on invalid TOML. Wrap calls in a try-catch block or create a custom wrapper class (e.g., `TomlParser`) to catch exceptions and return structured error responses. For CLI tools or APIs, log errors and return user-friendly messages instead of exposing raw exceptions.
Is the AST (Abstract Syntax Tree) API useful for Laravel developers, or should I stick to `parseToArray()`?
The AST API is overkill for most Laravel use cases like config loading. Use `parseToArray()` for simplicity and performance. Reserve the AST for advanced scenarios like TOML linting, custom validators, or modifying TOML documents programmatically before encoding them back to strings.
Can I dynamically generate TOML files at runtime, like for feature flags or A/B test rules?
Yes, use `Toml::encode()` to convert PHP arrays to TOML strings at runtime. For example, generate feature flags dynamically and write them to a TOML file: `$toml = (string) Toml::encode(['new_ui' => ['enabled' => true]]); file_put_contents('config/feature-flags.toml', $toml);`.
What are the performance implications of parsing large TOML files in Laravel?
No benchmarks are provided, but parsing large TOML files (e.g., 10KB+) could impact startup time. Test with your specific files and compare against alternatives like `spatie/toml`. Optimize by caching parsed configs in Laravel’s cache or using lazy-loading for non-critical configurations.
Are there any alternatives to this package for Laravel TOML support?
Yes, alternatives include `spatie/toml`, which supports older PHP versions (7.4+) and has a larger community. However, `internal/toml` offers TOML 1.1 compliance and a cleaner API for PHP 8.1+. Choose based on your PHP version and whether you need TOML 1.1 features.
How do I integrate this package with Laravel’s service container to load TOML configs?
Register a config loader in a Laravel service provider (e.g., `ConfigServiceProvider`). Bind a custom loader to the `config.loader` key, then configure it to parse TOML files from the `config/` directory. For example: `$this->app->bind('config.loader', fn() => new TomlConfigLoader());`, then use `config('database.host')` as usual.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor