https://docs.mongodb.com/php-library/v1.2/reference/method/MongoDBClient-selectCollection/#phpmethod.MongoDB\Client::selectCollection
use View, Input, Redirect, Validator, Sentry, Hashids,Carbon\Carbon,MongoDB;
public static function connectMongo($database)
{
$mongo = new MongoDB\Client('mongodb://', array(
'username' => '',
'password' => '',
'db' => 'database'
));
return $db = $mongo->selectDatabase($database);
}
public static function tableMongo($table)
{
$db=\Timelinemongo::connectMongo("database");
return $collection = $db->selectCollection($table);
}
public static function Timelineekle($sepet_id, $satis_durumu, $aciklama)
{
$kullanici = \Sentry::getUser();
$timeline=array();
$timeline["sepet_id"]=$sepet_id;
$timeline["durum"]=$satis_durumu;
$timeline["kayit_yapan_id"]=$kullanici->id;
$timeline["kayit_yapan_ad"]=$kullanici->first_name;
$timeline["kayit_yapan_soyad"]=$kullanici->last_name;
$timeline["aciklama"]=$aciklama;
$timeline["created_at"]=date('Y-m-d H:i:s');
//mongodb ye yerleştir---------------------------------------------------------------------------------------------------
$db=\Timelinemongo::connectMongo("database");
$mongoekle=\Timelinemongo::tableMongo('timeline');
$mongoekle->insertOne($timeline);
}
public function timelinesepet($id)
{
$sepet_id = \Hashids::decode($id)[0];
$sepet= \Sepet::find($sepet_id);
$donus=array();
$db=\Timelinemongo::connectMongo("database");
$islemler =\Timelinemongo::tableMongo('timeline');
// Koşulu tanımlıyorum.
$where = array('sepet_id' => $sepet_id);
// Sıralamayı belirliyorum. (1 : ASC , -1 : DESC)
$orderBy = array('created_at' => -1);
// Kayıtları Çekiyorum.
$timelines = $islemler->find($where)->sort($orderBy);
$timelines = \Timelinesepet::where("sepet_id", $sepet_id)->orderBy('id', 'desc')->get();
return View::make('Timeline::timelinesepet')->with("timelines",$timelines)->with("sepet",$sepet);
}
Read More