7 changed files with 161 additions and 10 deletions
-
29app/Http/Controllers/BirthdayController.php
-
27app/User.php
-
9resources/lang/id/birthday.php
-
46resources/views/birthdays/index.blade.php
-
11resources/views/layouts/partials/nav.blade.php
-
2routes/web.php
-
47tests/Unit/UserTest.php
@ -0,0 +1,29 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers; |
||||
|
|
||||
|
use App\User; |
||||
|
use Carbon\Carbon; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class BirthdayController extends Controller |
||||
|
{ |
||||
|
public function index() |
||||
|
{ |
||||
|
$userBirthdayQuery = User::whereNotNull('dob') |
||||
|
->select('users.name', |
||||
|
'users.dob', |
||||
|
'users.id as user_id' |
||||
|
); |
||||
|
|
||||
|
$currentMonth = Carbon::now()->format('m'); |
||||
|
$nextMonth = Carbon::now()->addMonth()->format('m'); |
||||
|
$userBirthdayQuery->whereIn(DB::raw("month(dob)"), [$currentMonth, $nextMonth]); |
||||
|
|
||||
|
$users = $userBirthdayQuery->get()->filter(function ($user) { |
||||
|
return $user->birthday_remaining < 60 && $user->birthday_remaining >= 0; |
||||
|
})->sortBy('birthday_remaining'); |
||||
|
|
||||
|
return view('birthdays.index', compact('users', 'currentMonth', 'nextMonth')); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
'birthday' => 'Ulang Tahun', |
||||
|
'upcoming' => 'Ulang tahun akan datang', |
||||
|
'remaining' => ':count hari', |
||||
|
'age_years' => ':age tahun', |
||||
|
'days' => 'Hari', |
||||
|
]; |
||||
@ -0,0 +1,46 @@ |
|||||
|
@extends('layouts.app') |
||||
|
|
||||
|
@section('title', __('user.upcoming_birthday')) |
||||
|
|
||||
|
@section('content') |
||||
|
|
||||
|
<div class="row"> |
||||
|
<div class="col-md-8 col-md-offset-2"> |
||||
|
<div class="panel panel-default text-center"> |
||||
|
<div class="panel-heading text-left"> |
||||
|
<h3 class="panel-title">{{ __('birthday.upcoming') }}</h3> |
||||
|
</div> |
||||
|
<table class="table table-condensed"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<td>#</td>
|
||||
|
<td class="text-left">{{ __('user.name') }}</td> |
||||
|
<td>{{ __('birthday.birthday') }}</td> |
||||
|
<td>{{ __('user.age') }}</td> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
@php |
||||
|
$no = 1; |
||||
|
@endphp |
||||
|
@forelse($users as $key => $user) |
||||
|
<tr> |
||||
|
<td>{{ $no++ }}</td> |
||||
|
<td class="text-left">{{ $user->name }}</td> |
||||
|
<td> |
||||
|
{{ $user->birthday->format('j M') }} |
||||
|
({{ __('birthday.remaining', ['count' => $user->birthday_remaining]) }}) |
||||
|
</td> |
||||
|
<td>{{ __('birthday.age_years', ['age' => $user->age]) }}</td> |
||||
|
</tr> |
||||
|
@empty |
||||
|
<tr> |
||||
|
<td colspan="4">{{ __('user.no_upcoming_birthday', ['days' => 60]) }}</td> |
||||
|
</tr> |
||||
|
@endforelse |
||||
|
</tbody> |
||||
|
</table> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
@endsection |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue