PHP code example of imanrjb / laravel-mongodb

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

    

imanrjb / laravel-mongodb example snippets


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

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

$app->withEloquent();

use ImanRjb\Mongodb\Eloquent\Model;

class User extends Model {}

use ImanRjb\Mongodb\Eloquent\Model;

class MyModel extends Model {

    protected $connection = 'mongodb';

}

DB::connection('mongodb')->beginTransaction();

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