DashboardController.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Member;
  4. use App\Models\Mutation;
  5. use App\Models\TypeMember;
  6. use App\Models\TypeVehicle;
  7. use App\Services\MutationService;
  8. use Carbon\Carbon;
  9. use Illuminate\Http\Request;
  10. class DashboardController extends Controller
  11. {
  12. /**
  13. * Handle the incoming request.
  14. *
  15. * @param \Illuminate\Http\Request $request
  16. * @return \Illuminate\Http\Response
  17. */
  18. public function __invoke(Request $request)
  19. {
  20. $member = Member::get();
  21. $typeMember = TypeMember::get();
  22. $typeVehicle = TypeVehicle::get();
  23. $mutation = Mutation::whereYear('created_at', date('Y'))
  24. ->get()
  25. ->groupBy([
  26. fn($mutation) => $mutation->type,
  27. fn($mutation) => Carbon::parse($mutation->getRawOriginal('created_at'))->format('M'),
  28. ]);
  29. return inertia('home/Index.vue', [
  30. 'cardStatistics' => [
  31. // [
  32. // 'title' => ...,
  33. // 'icon' => ...',
  34. // 'amount' => ...,
  35. // 'amountLabel' => ...,
  36. // 'value' => ...,
  37. // ],
  38. [
  39. 'title' => __('words.member'),
  40. 'icon' => 'pi pi-id-card',
  41. 'amount' => $member->count(),
  42. 'amountLabel' => __('words.total'),
  43. ],
  44. [
  45. 'title' => __('words.type_member'),
  46. 'icon' => 'pi pi-id-card',
  47. 'amount' => $typeMember->count(),
  48. 'amountLabel' => __('words.total'),
  49. ],
  50. [
  51. 'title' => __('words.type_vehicle'),
  52. 'icon' => 'pi pi-car',
  53. 'amount' => $typeVehicle->count(),
  54. 'amountLabel' => __('words.total'),
  55. ],
  56. ],
  57. 'barStatistics' => [
  58. [
  59. 'title' => __('words.mutation_statistic'),
  60. 'description' => __('words.per_year') . ' ' . date('Y'),
  61. 'data' => (new MutationService)->statistic($mutation),
  62. ],
  63. ],
  64. ]);
  65. }
  66. }