PHPackages                             metalogico/laravel-mocka - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. metalogico/laravel-mocka

ActiveLibrary[Testing &amp; Quality](/categories/testing)

metalogico/laravel-mocka
========================

Laravel Mocka provides fake API responses to designated users while serving real data to everyone else. A drop-in replacement for Laravel's Http facade, perfect for app store submissions, demos, and testing without disrupting production traffic

v1.0.3(3mo ago)18313MITPHPPHP ^8.0

Since Aug 20Pushed 3mo agoCompare

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

READMEChangelog (4)Dependencies (5)Versions (6)Used By (0)

Laravel Mocka ☕
===============

[](#laravel-mocka-)

[![Latest Version on Packagist](https://camo.githubusercontent.com/10a7984b0d9c560e7b5e28e323b5753b663341c12db9114144b67fc108a30bb6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6574616c6f6769636f2f6c61726176656c2d6d6f636b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/metalogico/laravel-mocka)

Laravel Mocka provides fake API responses to designated users while serving real data to everyone else. A drop-in replacement for Laravel's Http facade, perfect for app store submissions, demos, and testing without disrupting production traffic.

Why Mocka?
----------

[](#why-mocka)

When your Laravel app calls external APIs (like DMS, MES, or any third-party service), you often need to provide mock responses for:

- 🍎 **App Store Reviews** - Apple and Google reviewers need working apps without real API access
- 🧪 **Testing Environments** - Stable, predictable responses for your test suite
- 👥 **Demo Users** - Showcase your app without depending on external services
- 🚀 **Development** - Work offline or with unstable external APIs

Features
--------

[](#features)

- 🎯 **User-specific mocking** - Mock responses only for designated users
- 🔄 **Drop-in replacement** - Use `MockaHttp` instead of Laravel's `Http` facade
- 📁 **File-based mocks** - Organize mock responses in PHP files
- 🎨 **Response templating** - Dynamic mock responses with Faker integration
- 📊 **Request logging** - Track which requests are mocked vs real
- ❌ **Error simulation** - Test failure scenarios easily
- 🛣️ **Header activator** - Enable/disable mocking via `X-Mocka` header
- 📝 **Force activation** - Enable/disable mocking via `withOptions(['mocka' => true])`
- 🐌 **Rate limiting simulation** - Simulate slow APIs delays for testing
- 🔍 **Advanced URL matching** - Regex, wildcards, and parameter matching (coming soon ™)
- ⌘ **Command Line tools** - List mappings
- ⚡ **Zero performance impact** - Only active for designated users

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

[](#installation)

You can install the package via composer:

```
composer require metalogico/laravel-mocka
```

Publish the config file:

```
php artisan vendor:publish --tag="mocka-config"
```

Quick Start
-----------

[](#quick-start)

### 1. Configure Mock Users

[](#1-configure-mock-users)

In your `.env` file:

```
MOCKA_ENABLED=true
MOCKA_USERS=reviewer@apple.com,tester@google.com,demo@yourapp.com
MOCKA_LOGS=true
```

### 2. Create Mock Files

[](#2-create-mock-files)

Create mock files in `resources/mocka/`:

**`resources/mocka/api.mock.php`**

```
