vendredi 2 juin 2017

Display Tutorials Based On Tutorial Date and Specified Timezone in Laravel

Please help. I'm working on a site that debut at specific date and time. Tutorials are being displayed to every students on date set on each tutorials. However, I want the tutorials to debut not just by the date and time set on each tutorials but also based on the timezone set on each tutorial. For example, if a tutorial is set to debut today at 8:00pm Eastern Standard Time (EST) of the United States, it should debut at that time instead of debuting at the application set timezone.

I wrote the below code using Laravel collection filter() which seems to do the track. However, the page is taking longer to load and I'm unable to use laravel paginate(). I need to use Laravel paginate() to reduce the number of records being pulled from the database. There are over four thousand tutorials. Please help.

// upcoming tutorials
$tutorials = Tutorial::orderBy('id', 'desc)->paginate(20);
$futureTuts = $tutorials->filter(function ($value, $key) {
    $today = new \DateTime('now');
    $show_date = new \DateTime($value->show_date, new \DateTimeZone($value->timezones->name));
    return $show_date > $today;
});

$upcoming_tuts = $futureTuts->all();

Please any solutions around this to be able to use Laravel default paginate(). I believe using Laravel pagination will cause the page to load faster. I'm using Laravel 5.4.

Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rOmgDz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire