Browse Source
Merge pull request #45 from nafiesl/birthday-list
Merge pull request #45 from nafiesl/birthday-list
Add Birthday List Feature, resolves #41pull/60/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 174 additions and 30 deletions
-
2.travis.yml
-
30app/Http/Controllers/BirthdayController.php
-
27app/User.php
-
9resources/lang/en/birthday.php
-
9resources/lang/id/birthday.php
-
46resources/views/birthdays/index.blade.php
-
9resources/views/layouts/partials/nav.blade.php
-
17routes/api.php
-
2routes/web.php
-
4tests/Feature/ChangePasswordTest.php
-
47tests/Unit/UserTest.php
@ -0,0 +1,30 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers; |
||||
|
|
||||
|
use App\User; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class BirthdayController extends Controller |
||||
|
{ |
||||
|
public function index() |
||||
|
{ |
||||
|
$users = $this->getUpcomingBirthdays(); |
||||
|
|
||||
|
return view('birthdays.index', compact('users')); |
||||
|
} |
||||
|
|
||||
|
private function getUpcomingBirthdays() |
||||
|
{ |
||||
|
$birthdayDateRaw = "concat(YEAR(CURDATE()), '-', RIGHT(dob, 5)) as birthday_date"; |
||||
|
|
||||
|
$userBirthdayQuery = User::whereNotNull('dob') |
||||
|
->select('users.name', 'users.dob', 'users.id as user_id', DB::raw($birthdayDateRaw)) |
||||
|
->orderBy('birthday_date', 'asc') |
||||
|
->havingBetween('birthday_date', [today()->format('Y-m-d'), today()->addDays(60)->format('Y-m-d')]); |
||||
|
|
||||
|
$users = $userBirthdayQuery->get(); |
||||
|
|
||||
|
return $users; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
|
||||
|
return [ |
||||
|
'birthday' => 'Birhtday', |
||||
|
'upcoming' => 'Upcoming birthdays', |
||||
|
'remaining' => ':count days', |
||||
|
'age_years' => ':age years', |
||||
|
'days' => 'days', |
||||
|
]; |
||||
@ -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 |
||||
@ -1,18 +1 @@ |
|||||
<?php |
<?php |
||||
|
|
||||
use Illuminate\Http\Request; |
|
||||
|
|
||||
/* |
|
||||
|-------------------------------------------------------------------------- |
|
||||
| API Routes |
|
||||
|-------------------------------------------------------------------------- |
|
||||
| |
|
||||
| Here is where you can register API routes for your application. These |
|
||||
| routes are loaded by the RouteServiceProvider within a group which |
|
||||
| is assigned the "api" middleware group. Enjoy building your API! |
|
||||
| |
|
||||
*/ |
|
||||
|
|
||||
Route::middleware('auth:api')->get('/user', function (Request $request) { |
|
||||
return $request->user(); |
|
||||
}); |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue