unioil-mobile-api/app/Helpers/CurrentUserHelper.php

82 lines
1.9 KiB
PHP

<?php
namespace App\Helpers;
use Illuminate\Support\Facades\Auth;
use App\Admin;
use App\LoyaltyCard;
class CurrentUserHelper
{
public static function get_currentAdmin()
{
$auth = Auth::user();
if($auth)
{
$admin = Admin::where('username',$auth->username)
->where('is_active',1)
->get()
->first();
if($admin)
return $admin;
}
return null;
}
public static function getAdminName($id)
{
$admin = Admin::where('admin_id',$id)->get()->first();
if($admin)
return ucwords($admin->firstname." ".$admin->lastname);
else
return null;
}
public static function get_currentMember()
{
$auth = Auth::user();
if($auth)
{
$member = LoyaltyCard::with('personalDetails')
->join('users', 'loyalty_card.card_number' , '=', 'users.username')
->select('users.name', 'loyalty_card.*')
->where('loyalty_card.card_number',$auth->username)
->where('loyalty_card.is_active',1)
->get()
->first();
if($member)
return $member;
}
return null;
}
public static function get_currentUser()
{
$auth = Auth::user();
if($auth) return $auth;
return null;
}
public static function get_member_by_lcard($lcard_uuid)
{
$member = LoyaltyCard::with('personalDetails')
->where('lcard_uuid',$lcard_uuid)
->where('is_active',1)
->get()
->first();
if($member){
return $member;
}
}
}
?>