`защищенная функция getAllMonths () {
$ id = Auth :: user () -> accepttor_id;
$ month_array = array ();
$posts_dates = Sale::where('adoptor_id',$id)->whereYear('created_at',date('Y'))
->orderBy( 'created_at', 'ASC' )
->pluck( 'created_at');
$posts_dates = json_decode( $posts_dates );
if ( ! empty( $posts_dates ) ) {
foreach ( $posts_dates as $unformatted_date ) {
$date = new \DateTime( $unformatted_date);
$month_no = $date->format( 'm' );
$month_name = $date->format( 'F-Y' );
$month_array[ $month_no ] = $month_name;
}
}
return $month_array;
}
protected function getMonthlyPostCount( $month ) {
$year = date('Y');
$id = Auth::user()->adoptor_id;
$monthly_post_count = Sale::where('adoptor_id',$id)
->whereYear('created_at',$year)
->whereMonth('created_at', $month )
->sum('total');
return $monthly_post_count;
}
protected function salesData() {
$monthly_post_count_array = array();
$month_array = $this->getAllMonths();
$month_name_array = array();
if ( ! empty( $month_array ) ) {
foreach ( $month_array as $month_no => $month_name ){
$monthly_post_count = $this->getMonthlyPostCount( $month_no );
array_push( $monthly_post_count_array, $monthly_post_count );
array_push( $month_name_array, $month_name );
echo '<tr>
<td>'.$month_no.'</td>
<td>'.$month_name.'</td>
<td class="badge badge-success">'.number_format($monthly_post_count).'</td>
</tr>';
}
}
$max_no = max( $monthly_post_count_array );
$max = round($max_no * 1.5);
}`
затем отобразите его на графике, используя диаграмму js в качестве массива для страницы блейда