PHPackages                             lemaur/laravel-typed-config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lemaur/laravel-typed-config

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

lemaur/laravel-typed-config
===========================

0.1.0(2y ago)0956↑33.3%[2 PRs](https://github.com/leMaur/laravel-typed-config/pulls)MITPHPPHP ^8.1

Since May 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/leMaur/laravel-typed-config)[ Packagist](https://packagist.org/packages/lemaur/laravel-typed-config)[ Docs](https://github.com/lemaur/laravel-typed-config)[ RSS](/packages/lemaur-laravel-typed-config/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (4)Used By (0)

Laravel Typed Configuration
===========================

[](#laravel-typed-configuration)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5332be22d6a52716ba8bd7857d5e1a1e259e8233cef0e171c18b4654e20bec43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c656d6175722f6c61726176656c2d74797065642d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lemaur/laravel-typed-config)[![Total Downloads](https://camo.githubusercontent.com/d28083992e28002f5ee9897d335339e756243015105f40f4689bd8646e6dbceb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c656d6175722f6c61726176656c2d74797065642d636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lemaur/laravel-typed-config)[![License](https://camo.githubusercontent.com/7c9bc9bc1995d5c2c7e65d5ae323484073ab9fa4acdd243aae9404c42140a717/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c656d6175722f6c61726176656c2d74797065642d636f6e6669672e7376673f7374796c653d666c61742d73717561726526636f6c6f723d79656c6c6f77)](https://github.com/leMaur/laravel-typed-config/blob/main/LICENSE.md)[![Tests](https://camo.githubusercontent.com/fc87a14a7e0ef386f063bdb178d1837dff8168ffa43aec21f6e4940089977961/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c656d6175722f6c61726176656c2d74797065642d636f6e6669672f72756e2d74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/leMaur/laravel-typed-config/actions/workflows/run-tests.yml)[![GitHub Sponsors](https://camo.githubusercontent.com/67130ea26c0cdbb7c18af5c1fd1c7995f000bc3da607abffed1e39d789f48b2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f6c656d6175723f7374796c653d666c61742d73717561726526636f6c6f723d656134616161)](https://github.com/sponsors/leMaur)[![Trees](https://camo.githubusercontent.com/f12f2059f308501188008a8639ea876a9d8f8f3ce4047ea60b328985fc08b312/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f636f6c6f723d79656c6c6f77677265656e267374796c653d666c61742d737175617265266c6162656c3d54726565732671756572793d2532342e746f74616c2675726c3d68747470732533412532462532467075626c69632e6f66667365742e656172746825324675736572732532466c656d6175722532467472656573)](https://ecologi.com/lemaur?r=6012e849de97da001ddfd6c9)

This package provides an object-oriented way to retrieve the configuration data with the right type.

If you are familiar with static analysis tool like phpstan, you've probably encountered `Cannot cast mixed to string` error (or similar).

This is usually happen when you try to cast a value returned from a method/function with a `mixed` return type. Most of the time, in my personal case, the method is `config()` and following you can see an example:

```
$myValue = (string) config('my-app.my-value');
// or
$myValue = (string) config()->get('my-app.my-value');
```

With this package you can get a string value (and not only string) directly from the configuration like:

```
$myValue = config()->string('my-app.my-value');
```

Support Me
----------

[](#support-me)

Hey folks,

Do you like this package? Do you find it useful, and it fits well in your project?

I am glad to help you, and I would be so grateful if you considered supporting my work.

You can even choose 😃:

- You can [sponsor me 😎](https://github.com/sponsors/leMaur) with a monthly subscription.
- You can [buy me a coffee ☕ or a pizza 🍕](https://github.com/sponsors/leMaur?frequency=one-time&sponsor=leMaur) just for this package.
- You can [plant trees 🌴](https://ecologi.com/lemaur?r=6012e849de97da001ddfd6c9). By using this link we will both receive 30 trees for free and the planet (and me) will thank you.
- You can "Star ⭐" this repository (it's free 😉).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require lemaur/laravel-typed-config
```

Usage
-----

[](#usage)

### Retrieving Stringable Configuration Value

[](#retrieving-stringable-configuration-value)

You may use the `string` method to retrieve the configuration data as an instance of `Illuminate\Support\Stringable`:

```
$name = config()->string('my-app.name');
```

### Retrieving Boolean Configuration Value

[](#retrieving-boolean-configuration-value)

You may use the `boolean` method to retrieve the configuration data as a boolean. The `boolean` method returns `true` for 1, "1", true, "true", "on", and "yes". All other values will return `false`:

```
$archived = config()->boolean('my-app.archived');
```

### Retrieving Integer Configuration Value

[](#retrieving-integer-configuration-value)

You may use the `integer` method to retrieve the configuration data as an integer:

```
$count = config()->integer('my-app.count');
```

### Retrieving Float Configuration Value

[](#retrieving-float-configuration-value)

You may use the `float` method to retrieve the configuration data as a float:

```
$amount = config()->float('my-app.amount');
```

### Retrieving Date Configuration Value

[](#retrieving-date-configuration-value)

You may use the `date` method to retrieve the configuration data as a Carbon instance:

```
$birthday = config()->date('my-app.birthday');
```

The second and third arguments accepted by the `date` method may be used to specify the date's format and timezone, respectively:

```
$elapsed = config()->date('my-app.elapsed', '!H:i', 'Europe/Madrid');
```

In case of an invalid format, an `InvalidArgumentException` will be thrown.

### Retrieving Enum Configuration Value

[](#retrieving-enum-configuration-value)

You may use the `enum` method to retrieve the configuration data as a [PHP enum](https://www.php.net/manual/en/language.types.enumerations.php) instance. In case of an invalid value or the enum does not have a backing value that matches the input value, `null` will be returned. The `enum` method accepts the name of the input value and the enum class as its first and second arguments:

```
use App\Enums\Status;

$status = config()->enum('my-app.status', Status::class);
```

### Retrieving Configuration Value as a Collection

[](#retrieving-configuration-value-as-a-collection)

You may use the `collect` method to retrieve the configuration data as an `Illuminate\Support\Collection` instance:

```
$data = config()->collect('my-app.data');
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [leMaur](https://github.com/lemaur)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1080d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2696e190d36ed3a6809d954e3ae2153f969be340ef9b188f8a02bdc98b52f6c7?d=identicon)[leMaur](/maintainers/leMaur)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![leMaur](https://avatars.githubusercontent.com/u/2118799?v=4)](https://github.com/leMaur "leMaur (2 commits)")

---

Tags

configconfigurationlaraveltypetyped-configurationslaravelconfigurationconfiglemaurlaravel-typed-config

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lemaur-laravel-typed-config/health.svg)

```
[![Health](https://phpackages.com/badges/lemaur-laravel-typed-config/health.svg)](https://phpackages.com/packages/lemaur-laravel-typed-config)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
