Skip to content

Instantly share code, notes, and snippets.

View alaminfirdows's full-sized avatar
🎯

Al-Amin Firdows alaminfirdows

🎯
View GitHub Profile
import React, { useState } from 'react';
import axios from 'axios';
import classNames from 'classnames';
import { usePage } from '@inertiajs/react';
import { CommentType, PageProps, PostType, User } from '@/types';
import { formatDate } from '@/utils';
import CommentBox from './CommentBox';
type CommentProps = {
@alaminfirdows
alaminfirdows / has-many-deep.md
Last active May 1, 2024 10:45
Laravel Deep Relation Data Fetching

Deep Relations in Laravel: Handling Course-Episode Relationships

In Laravel, you often deal with relationships that span multiple tables. Here's a quick guide to counting related data through deep relations:

Option 1: Using hasManyThrough

When you store a direct reference like course_id in the episodes table, you can establish a deep relation using hasManyThrough. This is perfect for counting through intermediate relationships.

// file: Topic.php
<?php
use App\Services\ScrappingService;
$service = new ScrappingService();
$data = $service->fetchRecursive('https://google.com');
var_dump($data);
@alaminfirdows
alaminfirdows / outbound-email-with-cloudflare.md
Created January 24, 2024 07:20 — forked from irazasyed/outbound-email-with-cloudflare.md
Using Gmail SMTP with Cloudflare Email Routing: A Step-by-Step Guide

Using Gmail SMTP with Cloudflare Email Routing: Step-by-Step Guide

Learn how to send emails through Gmail SMTP with Cloudflare Email Routing in this comprehensive guide.

Step 1: Enable 2-Factor Authentication

To proceed with this method, ensure that you have enabled two-factor authentication for your Google account. If you haven't done so already, you can follow the link to set it up → Enable 2FA in your Google account.

Step 2: Create an App Password for Mail

<?php
$country_list = [
[
"name" => "Afghanistan",
"currency" => "AFN",
"continent" => "AS",
"code" => "AFG",
],
[
export const countriesFlag = [
{
emoji: '🇦🇫',
code: 'AF',
},
{
emoji: '🇦🇽',
code: 'AX',
},
{
@alaminfirdows
alaminfirdows / CopyToClipboard.ts
Created December 30, 2023 08:18
This JavaScript function, copyToClipboard, facilitates easy text copying to the clipboard. It first checks for compatibility with the modern Clipboard API in secure contexts. If supported, it uses the API for asynchronous clipboard writes. In cases where the API is unavailable or the context is not secure, it employs the 'out of viewport hidden …
export const copyToClipboard = async (textToCopy: string) => {
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(textToCopy);
} else {
// Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea');
textArea.value = textToCopy;
// Move textarea out of the viewport so it's not visible
export const copyToClipboard = async (textToCopy) => {
// Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(textToCopy);
} else {
// Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea');
textArea.value = textToCopy;
// Move textarea out of the viewport so it's not visible
@alaminfirdows
alaminfirdows / ExampleServiceProvider.php
Last active October 19, 2022 05:14
Example Service Provider for WPSmartPay
<?php
namespace Example\Providers;
use SmartPay\Framework\Support\ServiceProvider;
class ExampleServiceProvider extends ServiceProvider
{
public function register()
{
@alaminfirdows
alaminfirdows / code.php
Created September 19, 2022 12:03
Laravel rate limit/attempts by second
<?php
$shouldExecute = RateLimiter::attempt(
'browser_tracker' . geoip()->getClientIP(),
1, // max attempts
function () {
// your code here
},
2 // seconds
);