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
IlluminateSupportCollection {#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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Here is how you can achieve it
$created_at = Post::select(DB::raw('MONTH(created_at) as month'))->get();
If you want to get only simple array which is mostly we use in line graphs
$created_at = User::select(DB::raw('MONTH(created_at) as month'))->get(); $array = []; foreach($created_at as $month) { $array[] = $month->month; } dd($array);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0