1. Go to this page and download the library: Download mcbanks/mcbankslaravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mcbanks / mcbankslaravel example snippets
// Get all countries
$countries = Country::all();
// Get states for a specific country
$states = State::where('country_id', 1)->get();
// Get cities in a state
$cities = City::where('state_id', 1)->get();
// Get Kenyan counties
$counties = County::all();
// Get constituencies in a county
$constituencies = SubCounty::getUniqueConstituencies(1);
// Get wards in a constituency
$wards = SubCounty::getWardsByConstituency(1, 'changamwe');
// Get all wards in Kenya (filtered, no duplicates)
$allWards = SubCounty::getAllUniqueWards();
$user = User::find(1);
$user->assignRole('admin'); // Assign admin role
if ($user->hasRole('new_role')) {
return '/new-dashboard';
}
use App\Services\TwoFactorService;
$user = Auth::user();
$twoFactorService = app(TwoFactorService::class);
// Generate secret key and QR code
$secret = $twoFactorService->generateSecretKey($user);
$qrCode = $twoFactorService->generateQrCode($user, $secret);
// Enable 2FA after user verification
$twoFactorService->enable($user, $verificationCode);
// Check if user has 2FA enabled
if ($user->hasTwoFactorEnabled()) {
// Verify user code
if ($user->verifyTwoFactorCode($request->code)) {
// Authentication successful
$user->twoFactorAuthentication->updateLastUsed();
}
}
use App\Services\RateLimitingService;
$rateLimiting = app(RateLimitingService::class);
// Check authentication rate limit
if ($rateLimiting->checkAuthRateLimit($request)) {
abort(429, 'Too many attempts');
}
// Check API rate limit
if ($rateLimiting->checkApiRateLimit($request)) {
abort(429, 'API rate limit exceeded');
}
// Get rate limit information for current user
$status = $rateLimiting->getRateLimitStatus($request, 'auth', 5);
// Output rate limit headers
$headers = $rateLimiting->getRateLimitHeaders($request, 'api', 1000, 60);
foreach ($headers as $key => $value) {
$response->headers->set($key, $value);
}
// Blacklist an IP address
$rateLimiting->blacklistIp('192.168.1.100', 60); // 60 minutes
// Check if IP is blacklisted
if ($rateLimiting->isIpBlacklisted($request->ip())) {
abort(429, 'Your IP has been blocked');
}
// Remove IP from blacklist
$rateLimiting->unblacklistIp('192.168.1.100');
// Log suspicious activity for monitoring
$rateLimiting->logSuspiciousActivity($request, 'multiple_failed_logins');
// Check for suspicious activity patterns
if ($rateLimiting->checkSuspiciousActivityRateLimit($request)) {
// Take action against suspicious user
}
// Login attempts
RateLimitAuth: 5 attempts per 15 minutes
// Registration attempts
RateLimitAuth: 3 attempts per hour
// Password reset requests
RateLimitAuth: 3 attempts per hour
// Authenticated users
RateLimitApi: 1000 requests per hour
// Anonymous users
RateLimitApi: 100 requests per hour
// Specific endpoints
RateLimitApi: Custom limits per endpoint
// Profile updates
RateLimitProfile: 10 attempts per hour
// Avatar uploads
RateLimitProfile: 5 attempts per hour
// Profile views (more lenient)
RateLimitProfile: 200 attempts per hour
// Get user profile
$user = Auth::user();
$profile = $user->profile ?? $user->getOrCreateProfile();
// Check profile completion
if ($user->hasCompleteProfile()) {
// User has 80%+ complete profile
}
// Get avatar URL
$avatarUrl = $user->avatar_url;
$thumbnailUrl = $user->thumbnail_url;
// Calculate completion percentage
$percentage = $profile->calculateCompletionPercentage();
// Update completion percentage
$profile->updateCompletionPercentage();
// Get completion status message
$message = $profile->completion_percentage < 50
? 'Profile needs more information'
: 'Looking good!';
// Check if user can view another profile
if (auth()->user()->canViewProfile($targetUser)) {
// Show profile
}
// Get privacy settings
$privacy = $profile->privacy_settings;
$showPhone = $privacy['show_phone'] ?? true;
use App\Services\SocialAuthService;
// Handle social login
$socialUser = Socialite::driver('google')->user();
$user = $socialAuthService->handleSocialLogin('google', $socialUser);
// Check user social accounts
if ($user->hasSocialAccount('google')) {
$googleAccount = $user->getSocialAccount('google');
}
// Disconnect social account
$socialAuthService->disconnectSocialAccount($user, 'google');
// Get connected providers
$providers = $user->connected_providers; // ['google', 'github']
// Check token validity
$socialAccount = $user->getSocialAccount('google');
if ($socialAccount->hasValidToken()) {
// Token is valid
}
// Get provider-specific data
$avatar = $socialAccount->avatar_url;
$nickname = $socialAccount->nickname;
// Add new field
public $new_field = '';
// Add validation
protected $rules['new_field'] = ['
if ($user->hasRole('new_role')) {
return '/new-route';
}