PHPackages                             azmolla/app-context - 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. azmolla/app-context

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

azmolla/app-context
===================

Laravel App Context Helper — Safe global data accessor for application-wide settings.

1.0.0(8mo ago)00MITPHPPHP ^8.0|^8.1|^8.2|^8.3

Since Oct 20Pushed 8mo agoCompare

[ Source](https://github.com/AbiruzzamanMolla/app-context)[ Packagist](https://packagist.org/packages/azmolla/app-context)[ Docs](https://github.com/AbiruzzamanMolla/app-context)[ RSS](/packages/azmolla-app-context/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (2)Used By (0)

Azmolla App Context
===================

[](#azmolla-app-context)

A lightweight Laravel package that provides a **safe global application context** — allowing you to access configuration data (like site name, logo, contact info, etc.) from anywhere in your application, with automatic caching and graceful null handling.

---

🚀 Features
----------

[](#-features)

✅ Retrieve global data safely without null errors ✅ Works from Database, Cache, or Config ✅ View-shared `$appContext` variable ✅ Helper function `app_context()`✅ Supports auto-cache refresh ✅ Zero dependency, fast &amp; memory-safe

---

📦 Installation
--------------

[](#-installation)

```
composer require azmolla/app-context
```

Laravel will auto-discover the service provider.

---

⚙️ Publish Config &amp; Migration
---------------------------------

[](#️-publish-config--migration)

To customize settings or use database mode:

```
php artisan vendor:publish --tag=app-context-config
php artisan vendor:publish --tag=app-context-migrations
```

Then run the migration:

```
php artisan migrate
```

This creates the `app_context` table in your database.

---

🧩 Configuration
---------------

[](#-configuration)

```
return [
    'source' => env('APP_CONTEXT_SOURCE', 'database'), // database | cache | array
    'cache_key' => 'app_context',
    'cache_ttl' => 3600, // seconds
    'table' => 'app_context',
];
```

You can also use `.env`:

```
APP_CONTEXT_SOURCE=database

```

---

🧠 Usage
-------

[](#-usage)

### Option 1 — Using Helper Function

[](#option-1--using-helper-function)

```
app_context('site_name');          // returns value or null
app_context('site_name', 'MyApp'); // returns default if missing
```

Get all context values:

```
app_context(); // returns full array
```

---

### Option 2 — In Blade Templates

[](#option-2--in-blade-templates)

```
{{ $appContext->site_name }}
{{ $appContext->support_email ?? 'support@example.com' }}
```

The `$appContext` variable is **automatically shared** with all Blade views.

---

### Option 3 — In Controllers

[](#option-3--in-controllers)

```
use Illuminate\Support\Facades\Cache;

public function index()
{
    $context = app('app.context');
    $siteName = $context->site_name;

    return view('home', compact('siteName'));
}
```

---

🧰 Example Database Structure
----------------------------

[](#-example-database-structure)

idkeyvalue1site\_nameMy Laravel App2contact\_email3logo\_url/uploads/logo.png---

🧩 Extending
-----------

[](#-extending)

You can extend the class for custom logic:

```
class CustomContext extends \Azmolla\AppContext\Support\SafeAppContext
{
    public function getSiteTitle()
    {
        return strtoupper($this->site_name ?? 'DEFAULT SITE');
    }
}
```

---

🧪 Testing
---------

[](#-testing)

The package includes a basic PHPUnit test to validate functionality:

```
composer test
```

---

🪪 License
---------

[](#-license)

MIT License (see [LICENSE](LICENSE)).

---

👨‍💻 Author
----------

[](#‍-author)

**Abiruzzaman Molla**Backend Developer [LinkedIn](https://abiruzzamanmolla.github.io/)📧

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

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

257d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/20683047?v=4)[Abiruzzaman Molla](/maintainers/AbiruzzamanMolla)[@AbiruzzamanMolla](https://github.com/AbiruzzamanMolla)

---

Top Contributors

[![AbiruzzamanMolla](https://avatars.githubusercontent.com/u/20683047?v=4)](https://github.com/AbiruzzamanMolla "AbiruzzamanMolla (1 commits)")

---

Tags

laravelhelperdatasafeContextglobal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/azmolla-app-context/health.svg)

```
[![Health](https://phpackages.com/badges/azmolla-app-context/health.svg)](https://phpackages.com/packages/azmolla-app-context)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)[firefly-iii/data-importer

Firefly III Data Import Tool.

8045.8k](/packages/firefly-iii-data-importer)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2519.3k](/packages/iteks-laravel-enum)

PHPackages © 2026

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