Change db to database in database.php file for connecting with mongodb.
After than clear the cache for configurations
php artisan config:clear
use MongoDB\BSON\ObjectID as MongoID;
function convert_to_mongo_date($date)
{
if($date == null || !isset($date))
return null;
$carbon_date = Carbon::createFromFormat('d/m/Y', $date);
try {
$mongo_date = new MongoDate(strtotime($carbon_date->toDateString()) * 1000);
return $mongo_date;
}
catch(Exception $e) {
Log::info('MongoDate conversion error '.$e);
return new MongoDate();
}
}
function convert_to_date_from_sec($date)
{
if($date == null || !isset($date))
return "01/01/1990";
try
{
$secs = $date->toDateTime()->format('U.u');
return date('d/m/Y', $secs);
}
catch(Exception $e)
{
return "01/01/1990";
}
}
$fromDate = new MongoDate( strtotime('-1 month' ));
$currentDate = new MongoDate( strtotime('+1 day' ));
$user_signups_raw = DB::collection('users')->raw(function($collection) use($fromDate, $currentDate) { return $collection->aggregate (
array (
array ( '$match' => array ( 'created_at' => array( '$gt' => $fromDate, '$lt' =>$currentDate) ) ), array ( '$group' => array ( '_id' => array( '$dayOfYear' => '$created_at', ), 'count' => array ( '$sum' => 1 ), 'date' => array ( '$first' => '$created_at' ) ) ), array ( '$sort' => array ( '_id' => 1 ), )
)
); });
$user_signups = [];
foreach ($user_signups_raw as $doc)
{
$item = json_encode( $doc->getArrayCopy());
$item = $doc->getArrayCopy();
array_push($user_signups, $item);
}
strtotime('today' + '90 days')
date("Y-m-d", strtotime("+30 days")
Create DateTime object from date string
new_expiry_date = strtotime(date("Y-m-d", strtotime("+30 days")));
Convert DateTime to MongoDate
new MongoDate($new_expiry_date);
//Adding days to mongodate
function add_days_mongodate($mongo_date, $days)
{
$expiry_date = strtotime(date("d-m-Y H:i:s", $mongo_date->sec));
$new_expiry_date = $expiry_date + ($days * 24 * 60 * 60); //Add 30 Days
return $new_expiry_date;
}
function convert_string_to_mongodate($date)
{
$carbon_date = Carbon::createFromFormat('d/m/Y', $date);
$mongo_date = new MongoDate(strtotime($carbon_date->toDateString()));
return $mongo_date;
}
// Calculate date from two datetime
function days_between($str_date1, $str_date2)
{
//Get 1 day in milliseconds
$one_day = 1000 * 60 * 60 * 24;
$date1 = strtotime($str_date1);
$date2 = strtotime($str_date2);
$difference = $date1 - $date2;
$days = $difference/$one_day;
return $days;
}
// Calculate hours from two datetime
function hours_between($str_date1, $str_date2)
{
$date1 = strtotime($str_date1);
$date2 = strtotime($str_date2);
// Log::info($date1);
// Log::info($date2);
$difference = $date1 - $date2;
$hours = $difference/3600;
Log::info($hours);
return $hours;
}
//Format mongo date to displayable date string
function parse_mongo_date($mongo_date)
{
// $mongo_date == null
if(is_a($mongo_date, 'MongoDate'))
$new_date =date('d-m-Y H:i:s',$mongo_date->sec);
else
$new_date = $mongo_date;
return $new_date;
}
function convert_to_mongo_date($date)
{
return new MongoDate(strtotime(date(DATE_ISO8601, $date->sec)));
// new MongoDate(strtotime(date(DATE_ISO8601, $mongo_date->sec) - "30 days"));
}
function get_mongo_date_from_string($str_date)
{
$mongo_date = new MongoDate();
if(isset($str_date)) {
$carbon_date = Carbon::createFromFormat('d/m/Y', $str_date);
$mongo_date = new MongoDate(strtotime($carbon_date->toDateString()));
}
return $mongo_date;
// new MongoDate(strtotime(date(DATE_ISO8601, $mongo_date->sec) - "30 days"));
}
memory_limit
and set to 2048M"barryvdh/laravel-snappy": "0.2.*"
After updating composer, add the ServiceProvider to the providers array in app/config/app.phpBarryvdh\Snappy\ServiceProvider::class,
You can optionally use the facade for shorter code. Add this to your facades:'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class, 'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,
Using the wrapper:$pdf = App::make('snappy.pdf.wrapper'); $pdf->loadHTML('<h1>Test</h1>'); return $pdf->inline();
Or use the facade:$pdf = PDF::loadView('pdf.invoice', $data); return $pdf->download('invoice.pdf');
Important : You can publish the config-file to change some settings (default paper etc).php artisan vendor:publish