Items count of Last 7 days in Laravel
I am CS Student currently perusing my bachelor degree. I love coding and implementing new logics. Aside from that I'm also a hardware lover and has great interest in IOT.
Search for a command to run...
I am CS Student currently perusing my bachelor degree. I love coding and implementing new logics. Aside from that I'm also a hardware lover and has great interest in IOT.
No comments yet. Be the first to comment.
Create a .htaccess in the root of the directory and append this line anywhere in the file. AddHandler application/x-httpd-alt-php74___lsphp .php Here 74 represents PHP version 7.4. If we want 8.1, it would be 81.
We are going to create a local domain like app.local, Create a self-signed wildcard certificate which will works for subdomains as well and point the domain to a locally running site. Generate a self signed certificate https://www.brainbytez.nl/tutor...
GIT_COMMITTER_DATE="Sun Jul 16 14:00 2023 +0545" git commit --amend --date="Sun Jul 16 14:00 2023 +0545"
mkdir output && for file in *.heic; do heif-convert -q 100 "$file" "output/${file/%.heic/.jpg}"; done mkdir -p output && for file in *; do [[ $file == *.heic ]] && heif-convert -q 100 "$file" "output/${file/%.heic/.jpg}" || cp "$file" output/; done
https://dev.to/cloudx/how-to-use-puppeteer-inside-a-docker-container-568c Dockerfile FROM node:slim # We don't need the standalone Chromium ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true # Install Google Chrome Stable and fonts # Note: this installs the...
Here is a simple way to implement the items count along with date in past 7 days. Of course you can change the date range.
Here is the code for laravel controller
// $period = Amount of days you want to fetch data for.
// To change the days just change P40D with any other number of days like P{days}D and
// do corresponding in the sql query below by replacing 40 Days with other days.
$period = new DatePeriod((new DateTime())->sub(new DateInterval('P7D')), new DateInterval('P1D'), new DateTime());
$range = []; //variable to store all the date range from staring date to end date.
$dbData = []; //variable to store the final expected output
// Initialize all range with count 0
foreach ($period as $date) {
$range[$date->format("Y-m-d")] = 0;
}
// Fetch all data with in the staring and ending date.
$data = DB::table('table_name')
->selectRaw('DATE(created_at) as time, count(*) as count')
->whereDate('created_at', '>=', date_sub(date_create(), date_interval_create_from_date_string("7 days")))
->whereDate('created_at', '<=', date_create())
->groupBy('time')
->get();
// Once fetched, store the count values in the array.
foreach ($data as $val) {
$dbData[$val->time] = $val->count;
}
// Merge the two values
$data = array_replace($range, $dbData);
//return the result
return $data;
And you will get output like this.

Thats it. Happy Coding !