Skip to content

Instantly share code, notes, and snippets.

View jaygaha's full-sized avatar
🎯

Jay Gaha jaygaha

🎯
View GitHub Profile
@jaygaha
jaygaha / Setup-VS-Code-As-Laravel-Developer.md
Created April 17, 2025 01:30
A concise guide for Laravel developers to optimize VS Code with recommended settings.

Improve your VS Code as Laravel Developer

VS Code is a powerful and versatile code editor that can be customized to enhance your development experience as a Laravel developer. Here are my favorite settings:

Open the settings.json file in VS Code by pressing Ctrl + , or Cmd + ,.

Editor Settings

Font Family

@jaygaha
jaygaha / Managing-Inactive-Keys-in-Redis.md
Created March 11, 2025 08:05
Expire inactive Redis keys that haven't been accessed for over given time, ensuring efficient memory management and improved performance.

Remove Unused Idle Redis Items:

If an item lacks a TTL setting and is not in use, it will persist in the storage indefinitely unless deleted.

Run this command to delete stale items inside redis-cli:

eval "for _,k in ipairs(redis.call('keys', '*')) do if redis.call('object', 'idletime', k) > {SECONDS} then redis.call('expire', k, 1) end end" 0
@jaygaha
jaygaha / git-pr-template.md
Created February 27, 2025 03:00
GIT PR template

GIT Pull Request (PR) Template

New PR Process Template

1. Branch Naming

  • Use prefixes: feature/, bugfix/, or hotfix/ (e.g., feature/add-payment-gateway).

2. PR Title

@jaygaha
jaygaha / Git directory or filename rename.md
Created December 26, 2024 01:12
Rename a directory or file name in a Git repository that has already been pushed.

In a Git repository, how to properly rename a directory/file name already pushed?

Normally, simply renaming a directory or file name does not reflect in the remote repository.

Syntax:

git mv casesensitive tmp
git mv tmp CaseSensitive
@jaygaha
jaygaha / Clean Laravel large telescopes_entries.md
Created December 24, 2024 05:15
Purge Laravel large telescope entries

Delete Laravel large telescopes_entries.ibd

Delete large data table files in MySQL while using Laravel Telescopes

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE telescope_entries_tags;
TRUNCATE TABLE telescope_monitoring;
TRUNCATE TABLE telescope_entries;
SET FOREIGN_KEY_CHECKS = 1;
@jaygaha
jaygaha / laravel-unit-tests-connection.md
Created June 8, 2024 06:34
Override Model connections in Laravel for unit testing

Override Model connections in Laravel for unit testing

If you have specified a different connection that should be used when interacting with a particular model.

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
@jaygaha
jaygaha / soketi-laravel-sail-docker.md
Created May 29, 2024 07:55
Laravel Sail (Docker) + Soketi Setup

Soketi + Laravel Sail (Docker)

Soketi defaults to app-id, app-key, and app-secret after configuring broadcasting environment variables in the.env file. To use our own values, we should define them in docker-compose.yml as follows:

soketi:
    image: "quay.io/soketi/soketi:latest-16-alpine"
    environment:
 SOKETI_DEBUG: "1"
@jaygaha
jaygaha / ClearLaravelCaches.md
Created March 7, 2024 04:07
Using a single command, clear the Laravel caches

Clear Laravel caches using single command

To remove all Laravel caches, use a single artisan command, which saves you a lot of typing.

Instead of performing these individual commands,

$ php artisan cache:clear
$ php artisan config:clear
$ php artisan route:clear
@jaygaha
jaygaha / GetSenderInfoInMessageSendingEventListner.md
Created February 16, 2024 04:59
Get sender & receiver information in Mailable event listner in the Laravel

How to retrieve the name and email address in Laravel listner event to track emails status?

Laravel provides excellent support for email sending. Sometimes you need to record the status of outgoing emails in the system. You must construct two tables: email_logs and email_log_statuses. The 'email_logs' table contains all outgoing emails, while the email_log_statuses table contains all email statuses such as sent, failed, queued, scheduled to send, and so on.

Now, create Event Listeners During the email-sending process, Laravel triggers multiple events. You can set up event listeners to record these events and update the email log accordingly.

php artisan make:listener SendEmailListener --event='Illuminate\Mail\Events\MessageSending'
php artisan make:listener SentEmailListener --event='Illuminate\Mail\Events\MessageSent'
php artisan make:listener FailedEmailListener --event='Illuminate\Mail\Events\MessageFailed'
@jaygaha
jaygaha / laravel-sanctum-auto-logout.md
Created February 6, 2024 02:47
Laravel Sanctum auto logout if authenticated user remains idle for certain time

Laravel Sanctum auto logout if user remains idle for certain time

Ensuring the security of user sessions is critical in web applications, and Laravel Sanctum offers a strong solution for API authentication in Laravel projects. Implementing an automatic logout function when users are idle for an extended length of time is critical for improving security and user privacy. In this post, we'll look at how to integrate idle timeout capabilities with the Laravel API using Sanctum. Let's look at how to set up automated user logout for inactive sessions in a Laravel Sanctum-powered API.

Registering a custom validation with Sanctum

Open AuthServiceProvider.php and add this code accordingly to this file:

use Carbon\Carbon;