John Davidson

php - use timestamp type for line graph in laravel

0 comments
Message:


im going to use time which saved in database table


$created_at = DB::table('posts')->select('created_at')->get();

this return Collection with this format


Illuminate\Support\Collection {#1201 ▼
#items: array:5 [▼
0 => {#1209 ▼
+"created_at": "2021-04-18 11:17:37"
}
1 => {#1208 ▼
+"created_at": "2021-04-18 11:20:34"

now how can i filter just month ?


I need this for line graph



My Answer:
>pluck('created_at');

// Convert timestamp to Unix timestamp
$timestamps = [];
foreach ($created_at as $timestamp) {
$timestamps[] = strtotime($timestamp);
}

// Pass timestamps to view
return view('line-graph', ['timestamps' => $timestamps]);

Rate this post

3 of 5 based on 9858 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us