PHP code example of jeremy379 / laravel-disconnectable

1. Go to this page and download the library: Download jeremy379/laravel-disconnectable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeremy379 / laravel-disconnectable example snippets


use Illuminate\Database\Eloquent\Model;
use YourVendor\EloquentDisconnectable\Disconnectable;

class User extends Model
{
    use Disconnectable;
}

$transaction = User::with('order')->first();
$disconnected = $transaction->disconnect();

// Access normal attributes
echo $disconnected->id;

// Access already loaded relations
echo $disconnected->order->id;

// Attempting DB operations will fail
$disconnected->save();       // RuntimeException
$disconnected->load('cart'); // RuntimeException
$disconnected->otherRelation; // RuntimeException