<?php
namespace App\Http\Controllers\User;
use App\Constants\PaymentGatewayConst;
use App\Models\Card;
use App\Models\UserWallet;
use App\Models\Transaction;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Helpers\Response;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
class DashboardController extends Controller
{
/**
* Method for view index page
*/
public function index(){
$page_title = "Dashboard";
$user_wallet = UserWallet::with(['currency'])->auth()->first();
$card_payments = Card::auth()->where('default',true)->first();
$total_cards = Card::auth()->count();
$total_transactions = Transaction::auth()->count();
$transactions = Transaction::with(['card_method','payment_gateway'])->auth()
->orderBy('id','desc')->latest()->take(3)->get();
$add_money = Transaction::auth()->where('type',PaymentGatewayConst::ADDMONEY)->count();
$transfer_money = Transaction::auth()->where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->count();
$card_payment = Transaction::auth()->where('type',PaymentGatewayConst::CARD_PAYMENT)->count();
return view('user.dashboard',compact(
"page_title",
"user_wallet",
"card_payments",
'total_cards',
'transactions',
'total_transactions',
'add_money',
'transfer_money',
'card_payment'
));
}
public function getTransactionsByCard($id){
$transactions = Transaction::auth()->where('card_id', $id)->latest()->get();
return response()->json($transactions);
}
/**
* Method for user logout method
* @param Illuminate\Http\Request $request
*/
public function logout(Request $request) {
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect()->route('user.login');
}
/**
* Method for check wether user is valid or not
* @param Illuminate\Http\Request $request
*/
public function checkValidUser(Request $request){
$validator = Validator::make($request->all(),[
'email' => 'required|email'
]);
if($validator->fails()) return Response::validation(['error' => $validator->errors()->all()]);
$validated = $validator->validate();
$exist['data'] = User::where('email',$validated['email'])->first();
$user = auth()->user();
if(@$exist['data'] && $user->email == @$exist['data']->email){
return response()->json(['own'=>__("Can't transfer to your own account.")]);
}
return response($exist);
}
}
Save Cards
Simplify your payment experience by securely saving your card on our platform. After your initial transaction, you can choose to store your card details safely for future use. This feature eliminates the need to re-enter your payment information each time, making checkouts faster while keeping your data secure with advanced encryption and robust security measures.