Laravel State Management is a powerful, Redux-inspired solution for managing complex application state across services, requests, and caching layers. This package allows you to define shared state, easily persist and rehydrate data, and implement custom methods for state manipulation. With features like attribute casting, default state handling, and global store access, it provides a robust system for managing state across your Laravel app.
https://github.com/mustafakhaleddev/laravel-state-management
use App\Stores\UserStore;
// Store user data and persist it across requests
$user = User::first();
$userStore = StateManagement::store(UserStore::class);
$userStore->setUser($user);
$userStore->persist(); // Persist the state for future use
// Rehydrate and retrieve stored data later
$userStore->setKey($user->id);
$userStore->rehydrate();
echo $userStore->getUser()->name; // Output: User's name