Skip to content

Instantly share code, notes, and snippets.

View Mahendran-Balaji's full-sized avatar

Mahendran Balaji Mahendran-Balaji

View GitHub Profile
@Mahendran-Balaji
Mahendran-Balaji / loops.txt
Created November 12, 2023 20:40
Laravel Loops
$loop->index Returns a 0-based current loop iteration; 0 would mean the first iteration
$loop->iteration Returns a 1-based current loop iteration; 1 would mean the first iteration
$loop->remaining Number of iterations remaining in the loop; if there are a total of 10 iterations and the current iteration is 3, it would return 7
$loop->count Returns the total number of iterations or the total number of items in the array
$loop->first Returns true if it is the first iteration or item in the loop else returns false.
$loop->last Returns true if it is the last iteration or item in the loop else return false.
$loop->depth Returns the depth or nesting level of the current loop; returns 2 if it is a loop within a loop and 3 if it is nested one level more
$loop->parentIf this loop is nested within another @foreach loop, parent returns the parent’s loop variable; If it is not tested, returns null
@Mahendran-Balaji
Mahendran-Balaji / install-laravel-jetstream-inertia.txt
Created September 15, 2023 18:53
Laravel Inertia is a templating language and Inertia is working with vue js.
1) Install Laravel
composer create-project --prefer-dist laravel/laravel laravel_jetstream
2) Install Jetstream:
composer require laravel/jetstream
3) Create Auth with Inertia:
php artisan jetstream:install inertia
4) Now, let's node js package:
@Mahendran-Balaji
Mahendran-Balaji / push-existing-project-to-github.txt
Created August 28, 2023 18:03
Push existing project to GitHub
git init
git add .
git commit -m "Add existing project files to Git"
git remote add origin https://github.com/mahendran-balaji/example-website.git
git push -u -f origin master
@Mahendran-Balaji
Mahendran-Balaji / unsaved-changes-alert-to-user-using-javascript
Last active August 8, 2023 11:16
unsaved-changes-alert-to-user-using-javascript
window.addEventListener('beforeunload', function(e){
e.preventDefault();
e.returnvalue = '';
});
@Mahendran-Balaji
Mahendran-Balaji / use-laravel-default-response-code.php
Last active July 27, 2023 11:09
Example for 'How to use laravel default response code ?'
/* Open Response.php File From vendor/Symfony/http-foundation/ */
1) Refer attached File of Response.php
class Response
{
public const HTTP_CONTINUE = 100;
public const HTTP_SWITCHING_PROTOCOLS = 101;
public const HTTP_PROCESSING = 102; // RFC2518
public const HTTP_EARLY_HINTS = 103; // RFC8297
/* Javascript string replace spaces with dash using replace() */
/*
* Allowed only lower case letters (a-z)
* Here, the Regular expression is /\s+/g.
*/
$('#slug-url').bind('keyup blur', function() {
var $th = $(this);
$th.val($th.val().replace(/(\s{2,})|[^a-z ']/g, ' '));
@Mahendran-Balaji
Mahendran-Balaji / display-greeting-message-using-php.php
Last active July 26, 2023 05:40
Display Good Morning / Good Afternoon / Good Evening Message according to Current Time Using PHP
<?php
/* This sets the $time variable to the current hour in the 24 hour clock format */
$time = date("H");
/* Set the $timezone variable to become the current timezone */
$timezone = date("e");
/* If the time is less than 1200 hours, show good morning */
if ($time < "12") {
echo "Good morning";
} else
/* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */
@Mahendran-Balaji
Mahendran-Balaji / javascript-string-replace-more-space-into-single-space.js
Last active July 26, 2023 05:43
Allowed lower case (a-z), Upper Case (A-Z) and one space between the string using jQuery
/* javascript-string-replace-more-space-into-single-space */
$('#blogtitle').bind('keyup blur', function() {
var $th = $(this);
$th.val($th.val().replace(/(\s{2,})|[^a-zA-Z']/g, ' '));
$th.val($th.val().replace(/^\s*/, ''));
});