PHPackages                             mucan54/laravel-remote-eloquent - 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. [Database &amp; ORM](/categories/database)
4. /
5. mucan54/laravel-remote-eloquent

ActiveLibrary[Database &amp; ORM](/categories/database)

mucan54/laravel-remote-eloquent
===============================

Execute Eloquent queries on remote Laravel backend with automatic Row Level Security

v0(6mo ago)111MITPHPPHP ^8.1|^8.2|^8.3

Since Nov 5Pushed 6mo agoCompare

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

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

Laravel Remote Eloquent
=======================

[](#laravel-remote-eloquent)

**One package. Two modes. Same codebase.**

Execute Eloquent queries on a remote Laravel backend with automatic Row Level Security. Perfect for mobile apps and client applications.

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

[](#installation)

```
composer require mucan54/laravel-remote-eloquent
```

Publish configuration:

```
php artisan vendor:publish --tag=remote-eloquent-config
```

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

[](#configuration)

### Client Mode (Mobile App / Client Application)

[](#client-mode-mobile-app--client-application)

`.env`:

```
REMOTE_ELOQUENT_MODE=client
REMOTE_ELOQUENT_API_URL=https://api.yourapp.com
```

After login, store the token:

```
cache()->put('remote_eloquent_token', $token);
```

### Server Mode (Backend API)

[](#server-mode-backend-api)

**Install Laravel Sanctum** (recommended for mobile apps):

```
composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\ServiceProvider"
php artisan migrate
```

`.env`:

```
REMOTE_ELOQUENT_MODE=server
REMOTE_ELOQUENT_AUTH_MIDDLEWARE=auth:sanctum
```

`config/remote-eloquent.php`:

```
// Authentication (defaults to Sanctum)
'auth_middleware' => env('REMOTE_ELOQUENT_AUTH_MIDDLEWARE', 'auth:sanctum'),

// Model whitelist
'allowed_models' => [
    'Post',
    'Comment',
    'Product',
],
```

**Alternative authentication:**

```
// Laravel Passport
'auth_middleware' => 'auth:api',

// JWT Auth
'auth_middleware' => 'jwt.auth',

// Multiple middleware
'auth_middleware' => ['auth:sanctum', 'verified'],

// Disable authentication (NOT recommended)
'auth_middleware' => null,
```

Usage
-----

[](#usage)

### Same Model, Both Environments

[](#same-model-both-environments)

```
