PHPackages                             audunru/dynamic-cors - 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. audunru/dynamic-cors

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

audunru/dynamic-cors
====================

Dynamically change CORS options in Laravel

v2.0.6(6mo ago)32.3kMITPHPPHP ^8.2CI passing

Since May 20Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/audunru/dynamic-cors)[ Packagist](https://packagist.org/packages/audunru/dynamic-cors)[ RSS](/packages/audunru-dynamic-cors/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (16)Used By (0)

Dynamic CORS options in Laravel
===============================

[](#dynamic-cors-options-in-laravel)

[![Build Status](https://github.com/audunru/dynamic-cors/actions/workflows/validate.yml/badge.svg)](https://github.com/audunru/dynamic-cors/actions/workflows/validate.yml)[![Coverage Status](https://camo.githubusercontent.com/b468a69b97684c115cd71997adbce67d3c6e29f6b281e0612584c72f6e1190db/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f617564756e72752f64796e616d69632d636f72732f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/audunru/dynamic-cors?branch=main)[![StyleCI](https://camo.githubusercontent.com/45127b3bc26c7ce1975c9676d436d70a7a0e5e7df6dba4fa17c374ee2c7a4a26/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3830333430323537372f736869656c643f6272616e63683d6d61696e)](https://github.styleci.io/repos/803402577)

Typically used to configure custom allowed origins per user/account, so that your users can access your HTTP API from different domains without getting CORS errors.

Under the hood, this middleware dynamically sets Laravel's default CORS configuration options. Basically, it's a wrapper for calls like...

```
config("cors.allowed_origins", ["https://www.example.com"]);
```

... where the list of of allowed origins would dynamically change, for example come from the user's account settings.

Installation
============

[](#installation)

```
composer require audunru/dynamic-cors
```

You will have to replace Laravel's default `HandleCors` middleware with a version that extends `audunru\DynamicCors\Middleware\HandleCors`.

1. Ensure that you are [manually managing Laravel's default global middleware](https://laravel.com/docs/11.x/middleware#manually-managing-laravels-default-global-middleware).
2. Remove `\Illuminate\Http\Middleware\HandleCors::class` from the middleware stack.
3. Create a new file `app/Http/Middleware/UserCors.php`.

You can place this wherever you want, and of course name it according to what it does in your application.

This is an example where a user has a list of per-user allowed origins, perhaps controlled by themselves in the application UI.

```
namespace App\Http\Middleware;

use Closure;
use audunru\DynamicCors\Middleware\HandleCors;

class UserCors extends HandleCors
{
    public function handle($request, Closure $next)
    {
        $user = Auth::user();

        $this->allowedOrigins = array_merge(
            [config('app.url')],
            $user->allowedOrigins // Note: allowedOrigins does not exist by default, it's something you would have to create. Or make something completely different
        );

        return parent::handle($request, $next);
    }
}
```

`audunru\DynamicCors\Middleware\HandleCors` has protected properties for `allowedOrigins` and all the other CORS service settings. Any properties that you set in your middleware will be used by the CORS service. Properties that you don't set will use the value set in `cors.php`.

4. Add `\App\Http\Middleware\HandleCors::class` to the middleware stack.

Development
===========

[](#development)

Testing
-------

[](#testing)

Run tests:

```
composer test
```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance77

Regular maintenance activity

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 54.2% 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 ~49 days

Recently: every ~15 days

Total

12

Last Release

184d ago

Major Versions

v1.0.4 → v2.0.02025-03-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/444043228e007e4f695d18a30380b811fb60077138f7c46f111f45a1b98e2f1c?d=identicon)[audunru](/maintainers/audunru)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (39 commits)")[![audunru](https://avatars.githubusercontent.com/u/5163790?v=4)](https://github.com/audunru "audunru (22 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (10 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (1 commits)")

---

Tags

laravelcors

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/audunru-dynamic-cors/health.svg)

```
[![Health](https://phpackages.com/badges/audunru-dynamic-cors/health.svg)](https://phpackages.com/packages/audunru-dynamic-cors)
```

###  Alternatives

[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)
