PHP code example of make3782 / laravel-mongodb-transactions

1. Go to this page and download the library: Download make3782/laravel-mongodb-transactions 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/ */

    

make3782 / laravel-mongodb-transactions example snippets


//Jenssegers\Mongodb\MongodbServiceProvider::class,
Zs\Mongodb\MongodbServiceProvider::class,

//$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class);
$app->register(Zs\Mongodb\MongodbServiceProvider::class);

$app->withEloquent();

//use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Zs\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent {}

//use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Zs\Mongodb\Eloquent\Model as Eloquent;

class MyModel extends Eloquent {

    protected $connection = 'mongodb';

}

DB::beginTransaction();

try {
    User::insert($userData);
    UserInfo::insert($userInfoData);
    
    DB::commit();
} catch (\Exception $e) {
    DB::rollBack();
    throw $e;
}