PHPackages                             robtrehy/laravel-user-preferences - 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. robtrehy/laravel-user-preferences

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

robtrehy/laravel-user-preferences
=================================

A package for Laravel to store user preferences for your project.

4.1.3(6mo ago)35.6k3[1 PRs](https://github.com/RobTrehy/LaravelUserPreferences/pulls)MITPHPPHP ^8.1CI failing

Since Jan 22Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/RobTrehy/LaravelUserPreferences)[ Packagist](https://packagist.org/packages/robtrehy/laravel-user-preferences)[ RSS](/packages/robtrehy-laravel-user-preferences/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (15)Used By (0)

Laravel User Preferences
========================

[](#laravel-user-preferences)

[![](https://camo.githubusercontent.com/07fbdccb332743b789042d84d7a78736f785c59e6434ff8206ffc7b14cd2544d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f526f6254726568792f4c61726176656c55736572507265666572656e6365732f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/07fbdccb332743b789042d84d7a78736f785c59e6434ff8206ffc7b14cd2544d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f526f6254726568792f4c61726176656c55736572507265666572656e6365732f74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)[![](https://camo.githubusercontent.com/680e56ab1db43dfdd299a3da4f6238f9dcf908f9fea8be4cbadd46781defc8bc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f526f6254726568792f4c61726176656c55736572507265666572656e6365733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/680e56ab1db43dfdd299a3da4f6238f9dcf908f9fea8be4cbadd46781defc8bc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f526f6254726568792f4c61726176656c55736572507265666572656e6365733f7374796c653d666c61742d737175617265)[![](https://camo.githubusercontent.com/484f8db309cb67c06be9b5c1222c1e8b3fe521d1888856f3ba4c673bf2f531f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f526f6254726568792f4c61726176656c55736572507265666572656e6365733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/484f8db309cb67c06be9b5c1222c1e8b3fe521d1888856f3ba4c673bf2f531f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f526f6254726568792f4c61726176656c55736572507265666572656e6365733f7374796c653d666c61742d737175617265)[![](https://camo.githubusercontent.com/a58b2fa72174f11d77a7595d004b6aea1130078251edeb39865ba296cadaba9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6274726568792f6c61726176656c2d757365722d707265666572656e6365733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a58b2fa72174f11d77a7595d004b6aea1130078251edeb39865ba296cadaba9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f6274726568792f6c61726176656c2d757365722d707265666572656e6365733f7374796c653d666c61742d737175617265)[![](https://camo.githubusercontent.com/50659ae2de6580c9e7069595c4298f276fd66fbdcd92effcf8cef5eb2876e191/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6274726568792f6c61726176656c2d757365722d707265666572656e6365733f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/50659ae2de6580c9e7069595c4298f276fd66fbdcd92effcf8cef5eb2876e191/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6274726568792f6c61726176656c2d757365722d707265666572656e6365733f7374796c653d666c61742d737175617265)

This is a package for Laravel that can be used to store and access preferences of the currently authenticated user. The preferences are stored as JSON in a single database column. The default configuration stores this alongside the user record in the `users` table.

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

[](#installation)

1. Run `composer require robtrehy/laravel-user-preferences` to include this in your project.
2. Publish the config file with the following command ```
    php artisan vendor:publish --provider="RobTrehy\LaravelUserPreferences\UserPreferencesServiceProvider" --tag="config"

    ```
3. Modify the published configuration file to your requirements. The file is located at `config/user-preferences.php`.
4. Add the `preferences` column to the database. A migration file is included, just run the following command ```
    php artisan vendor:publish --provider="RobTrehy\LaravelUserPreferences\UserPreferencesServiceProvider" --tag="migrations" && php artisan migrate

    ```

    This will add the column defined in your configuration file to the table defined in your configuration file.

Configuration
-------------

[](#configuration)

Open `config/user-preferences.php` to adjust the package's configuration.

If this file doesn't exist, run `php artisan vendor:publish --provider="RobTrehy\LaravelUserPreferences\UserPreferencesServiceProvider" --tag="config"`to create the default configuration file.

Set `table`, `column`, and `primary_key` to match your requirements. `primary_key` should be the users id.

Laravel User Preferences uses the Laravel Cache driver to reduce the number of queries on your database. By default Laravel caches using the `file` driver. If you wish to disable this, you can use the `null` driver. The cache key supplied by Laravel User Preferences adds a prefix and suffix to the user's `id`. You can supply your own prefix and suffix by changing the `cache.prefix` and `cache.suffix` configuration values.

In the `defaults` array you can set your default values for user preferences.

#### Example configuration

[](#example-configuration)

```
'database' => [
    'table' => 'users',
    'column' => 'preferences',
    'primary_key' => 'id'
],
'cache' => [
    'prefix' => 'user-',
    'suffix' => '-preferences',
],
'defaults' => [
    'theme' => 'blue',
    'show_welcome' => true
]

```

Usage
-----

[](#usage)

### Set a preference

[](#set-a-preference)

Use this method to set a preference for the **currently authenticated user**:

```
UserPreferences::set(string $setting, $value);
```

### Get a preference

[](#get-a-preference)

Get the value of a preference for the **currently authenticated user**:

```
UserPreferences::get(string $setting);
```

### Reset a preference

[](#reset-a-preference)

Reset a single preference for the **currently authenticated user**:

```
UserPreferences::reset(string $setting);
```

### Reset all default preferences

[](#reset-all-default-preferences)

Reset all default preferences for the **currently authenticated user**:

```
UserPreferences::setDefaultPreferences();
```

### Get all preferences

[](#get-all-preferences)

Get all preferences for the **currently authenticated user**:

```
UserPreferences::all();
```

### Check if a preference exists

[](#check-if-a-preference-exists)

Check if the **currently authenticated user** has a specific preference:

```
UserPreferences::has(string $setting);
```

### Save a preference

[](#save-a-preference)

All preferences are saved automatically when `UserPreferences::set()` is called.

---

New: Arbitrary User Methods
---------------------------

[](#new-arbitrary-user-methods)

You can now work with preferences for **any user instance or ID**, not just the currently authenticated user.

### Get a preference for a specific user

[](#get-a-preference-for-a-specific-user)

```
UserPreferences::getForUser(string $setting, User|int $user);
```

- `$user` can be a `User` model instance or a user ID.
- Returns the preference value if set, otherwise the default.

### Set a preference for a specific user

[](#set-a-preference-for-a-specific-user)

```
UserPreferences::setForUser(string $setting, $value, User|int $user);
```

- `$user` can be a `User` model instance or a user ID.
- Saves the preference for that user without affecting the currently authenticated user.

### Reset a preference for a specific user

[](#reset-a-preference-for-a-specific-user)

```
UserPreferences::resetForUser(string $setting, User|int $user);
```

- Returns `true` if the default was restored, `false` if the preference was deleted.

### Check if a specific user has a preference

[](#check-if-a-specific-user-has-a-preference)

```
UserPreferences::hasForUser(string $setting, User|int $user);
```

- Returns `true` if a value exists, `false` otherwise.

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

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

[](#security-vulnerabilities)

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

License
-------

[](#license)

This Laravel package is free software distributed under the terms of the MIT license. See [LICENSE](LICENSE)

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance69

Regular maintenance activity

Popularity27

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 85.1% 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

Every ~191 days

Recently: every ~25 days

Total

14

Last Release

184d ago

Major Versions

v1.0.1 → 2.0.02021-04-06

2.1.1 → 3.0.02023-02-10

3.1.1 → 4.0.02025-08-01

PHP version history (4 changes)v1.0.0PHP &gt;=7.0

2.0.0PHP ^7.3|^8.0

3.0.0PHP ^8.0

4.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/ae6a42c48ab7778d5e08e28682c26c2556048e715309d1db7df63ae0bfdb0f80?d=identicon)[RobTrehy](/maintainers/RobTrehy)

---

Top Contributors

[![RobTrehy](https://avatars.githubusercontent.com/u/13102009?v=4)](https://github.com/RobTrehy "RobTrehy (80 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![sunscreem](https://avatars.githubusercontent.com/u/7523595?v=4)](https://github.com/sunscreem "sunscreem (4 commits)")[![fefo-p](https://avatars.githubusercontent.com/u/42467872?v=4)](https://github.com/fefo-p "fefo-p (3 commits)")[![daniego](https://avatars.githubusercontent.com/u/14246141?v=4)](https://github.com/daniego "daniego (2 commits)")[![Reex11](https://avatars.githubusercontent.com/u/16672241?v=4)](https://github.com/Reex11 "Reex11 (1 commits)")

---

Tags

laraveluser-preferences

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/robtrehy-laravel-user-preferences/health.svg)

```
[![Health](https://phpackages.com/badges/robtrehy-laravel-user-preferences/health.svg)](https://phpackages.com/packages/robtrehy-laravel-user-preferences)
```

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

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