Skip to content

Commit

Permalink
feat: add 2FA in Profile, Donatur, Donation and Campaign model and ctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
arief-github committed Apr 28, 2024
1 parent 9dc7dfb commit 783565d
Show file tree
Hide file tree
Showing 13 changed files with 611 additions and 10 deletions.
47 changes: 47 additions & 0 deletions app/Http/Controllers/Admin/DonationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Donation;

class DonationController extends Controller
{
/**
* index
*
* @return void
*/

public function index()
{
return view('admin.donation.index');
}


public function filter(Request $request)
{
$this->validate($request, [
'date_from' => 'required',
'date_to' => 'required'
]);

$date_from = $request->date_from;
$date_to = $request->date_to;

// get data donation by range date
$donations = Donation::where('status', 'success')
->whereDate('created_at', '>=', $request->date_from)
->whereDate('created_at', '<=', $request->date_to)
->get();

// get total donation by range date
$total = Donation::where('status', 'success')
->whereDate('created_at', '>=', $request->date_from)
->whereDate('created_at', '<=', $request->date_to)
->sum('amount');

return view('admin.donation.index', compact('donations', 'total'));
}
}
20 changes: 20 additions & 0 deletions app/Http/Controllers/Admin/DonaturController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Donatur;

class DonaturController extends Controller
{
// show all donatur data registered
public function index()
{
$donaturs = Donatur::latest()->when(request()->q, function($donaturs) {
$donaturs = $donaturs->where('name', 'like', '%'. request()->q . '%');
})->paginate(10);

return view('admin.donatur.index', compact('donaturs'));
}
}
19 changes: 19 additions & 0 deletions app/Http/Controllers/Admin/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ProfileController extends Controller
{
/**
* index
*
* @return void
*/
public function index()
{
return view('admin.profile.index');
}
}
61 changes: 61 additions & 0 deletions app/Http/Controllers/Api/CampaignController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Campaign;
use App\Models\Donation;

class CampaignController extends Controller
{
/**
* index
*/

public function index()
{
// get data campaigns
$campaigns = Campaign::with('user')->with('sumDonation')->when(request()->q, function($campaigns) {
$campaigns = $campaigns->where('title', 'like', '%'.request()->q.'%');
})->latest()->paginate(5);

// return with response JSON
return response()->json([
'success' => true,
'message' => 'List Data Campaigns',
'data' => $campaigns,
], 200);
}

/**
* A description of the entire PHP function.
*
* @param datatype $slug description
* @throws Some_Exception_Class description of exception
* @return Some_Return_Value
*/

public function show($slug)
{
// get data campaign by slug
$campaign = Campaign::with('user')->with('sumDonation')->where('slug', $slug)->first();

// get data donation by campaign
$donations = Donation::with('donatur')->where('campaign_id', $campaign->id)->where('status', 'success')->latest()->get();

if(!$campaign) {
return response()->json([
'success' => false,
'message' => 'Data Campaign Tidak Ditemukan',
], 404);
}

return response()->json([
'success' => true,
'message' => 'Detail Data Campaign : '.$campaign->title,
'data' => $campaign,
'donations' => $donations
], 200);
}
}
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;

class User extends Authenticatable
{
use HasFactory, Notifiable;
use HasFactory, Notifiable, TwoFactorAuthenticatable;

/**
* The attributes that are mass assignable.
Expand Down
99 changes: 99 additions & 0 deletions resources/views/admin/donation/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@extends('layouts.app', ['title' => 'Donation - Admin'])

@section('content')
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-300">
<div class="container mx-auto px-6 py-8">
<form action="{{ route('admin.donation.filter') }}" method="GET">
<div class="flex gap-6">
<div class="flex-auto">
<label class="text-gray-700" for="name">TANGGAL AWAL</label>
<input class="form-input w-full mt-2 rounded-md bg-white p-3 shadow-md" type="date" name="date_from"
value="{{ old('date_form') ?? request()->query('date_from') }}">
@error('date_from')
<div class="w-full bg-red-200 shadow-sm rounded-md overflow-hidden mt-2">
<div class="px-4 py-2">
<p class="text-gray-600 text-sm">{{ $message }}</p>
</div>
</div>
@enderror
</div>

<div class="flex-auto">
<label class="text-gray-700" for="name">TANGGAL AKHIR</label>
<input class="form-input w-full mt-2 rounded-md bg-white p-3 shadow-md" type="date" name="date_to"
value="{{ old('date_to') ?? request()->query('date_to') }}">
@error('date_to')
<div class="w-full bg-red-200 shadow-sm rounded-md overflow-hidden mt-2">
<div class="px-4 py-2">
<p class="text-gray-600 text-sm">{{ $message }}</p>
</div>
</div>
@enderror
</div>

<div class="flex-1">
<button type="submit"
class="mt-8 w-full p-3 bg-gray-600 text-gray-200 rounded-md shadow-md hover:bg-gray-700 focus:outline-none focus:bg-gray-700">FILTER</button>
</div>
</div>
</form>

@if($donations ?? '')
@if(count($donations) > 0)
<div class="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
<div class="inline-block min-w-full shadow-sm rounded-lg overflow-hidden">
<table class="min-w-full table-auto">
<thead class="justify-between">
<tr class="bg-gray-600 w-full">
<th class="px-16 py-2">
<span class="text-white">NAMA DONATUR</span>
</th>
<th class="px-16 py-2 text-left">
<span class="text-white">CAMPAIGN</span>
</th>
<th class="px-16 py-2 text-left">
<span class="text-white">TANGGAL</span>
</th>
<th class="px-16 py-2 text-center">
<span class="text-white">JUMLAH DONASI</span>
</th>
</tr>
</thead>
<tbody class="bg-gray-200">
@forelse($donations as $donation)
<tr class="border bg-white">
<td class="px-16 py-2 flex justify-center">
{{ $donation->donatur->name }}
</td>
<td class="px-16 py-2">
{{ $donation->campaign->title }}
</td>
<td class="px-16 py-2">
{{ $donation->created_at }}
</td>
<td class="px-5 py-2 text-right">
{{ moneyFormat($donation->amount) }}
</td>
</tr>
@empty
<div class="bg-red-500 text-white text-center p-3 rounded-sm shadow-md">
Data Belum Tersedia!
</div>
@endforelse
<tr class="border bg-gray-600 text-white font-bold">
<td colspan="3" class="px-5 py-2 justify-center">
TOTAL DONASI
</td>
<td colspan="3" class="px-5 py-2 text-right">
{{ moneyFormat($total) }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
@endif
@endif
</div>
</main>
@endsection
66 changes: 66 additions & 0 deletions resources/views/admin/donatur/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@extends('layouts.app', ['title' => 'Donatur - Admin'])

@section('content')
<main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-300">
<div class="container mx-auto px-6 py-8">

<div class="flex items-center">
<div class="relative">
<span class="absolute inset-y-0 left-0 pl-3 flex items-center">
<svg class="h-5 w-5 text-gray-500" viewBox="0 0 24 24" fill="none">
<path
d="M21 21L15 15M17 10C17 13.866 13.866 17 10 17C6.13401 17 3 13.866 3 10C3 6.13401 6.13401 3 10 3C13.866 3 17 6.13401 17 10Z"
stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round" />
</svg>
</span>
<form action="{{ route('admin.donatur.index') }}" method="GET">
<input class="form-input w-full rounded-lg pl-10 pr-4" type="text" name="q" value="{{ request()->query('q') }}"
placeholder="Search">
</form>
</div>
</div>

<div class="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
<div class="inline-block min-w-full shadow-sm rounded-lg overflow-hidden">
<table class="min-w-full table-auto">
<thead class="justify-between">
<tr class="bg-gray-600 w-full">
<th class="px-16 py-2">
<span class="text-white">NAMA LENGKAP</span>
</th>
<th class="px-16 py-2 text-left">
<span class="text-white">EMAIL</span>
</th>
</tr>
</thead>
<tbody class="bg-gray-200">
@forelse($donaturs as $donatur)
<tr class="border bg-white">

<td class="px-5 py-2">
{{ $donatur->name }}
</td>

<td class="px-16 py-2">
{{ $donatur->email }}
</td>

</tr>
@empty
<div class="bg-red-500 text-white text-center p-3 rounded-sm shadow-md">
Data Belum Tersedia!
</div>
@endforelse
</tbody>
</table>
@if ($donaturs->hasPages())
<div class="bg-white p-3">
{{ $donaturs->links('vendor.pagination.tailwind') }}
</div>
@endif
</div>
</div>
</div>
</main>
@endsection
Loading

0 comments on commit 783565d

Please sign in to comment.