Skip to content

Instantly share code, notes, and snippets.

View dhruva81's full-sized avatar
🏠
Working from home

Dhruva dhruva81

🏠
Working from home
View GitHub Profile
@dhruva81
dhruva81 / all.tsx
Created June 1, 2024 18:08 — forked from ivandoric/all.tsx
Infinite Scroll And Filters With React Query
import Container from "components/ui/Container"
import VideoCard from "components/VideoCard"
import fetchData from "helpers/fetchData"
import { useEffect, useState, Fragment, useRef } from "react"
import { useInfiniteQuery } from "react-query"
import useIntersectionObserver from "../hooks/useIntersectionObserver"
import Select from "react-select"
import { useUIDSeed } from "react-uid"
import { useRouter } from "next/router"
import Seo from "components/Seo"
@dhruva81
dhruva81 / laravel-subdirectory.conf
Created January 21, 2024 11:56 — forked from tsolar/laravel-subdirectory.conf
Laravel in subdirectory nginx example
server {
client_body_in_file_only clean;
client_body_buffer_size 32K;
client_max_body_size 300M;
sendfile on;
send_timeout 300s;
# Port that the web server will listen on.
#listen 80;
@dhruva81
dhruva81 / AddressComponent.php
Created December 4, 2023 15:14 — forked from websmithcode/AddressComponent.php
FilamentPHP Composite address field
<?php
namespace App\Filament\Resources;
use Filament\Forms\Components;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Set;
use Illuminate\Support\Str;
use LiveWire\Component as Livewire;
@dhruva81
dhruva81 / CopyToClipboardAction.php
Created November 13, 2023 18:31 — forked from Z3d0X/CopyToClipboardAction.php
Filament CopyToClipboardAction
<?php
namespace App\Filament\Pages\Actions;
use Closure;
use Filament\Pages\Actions\Action as BaseAction;
use Illuminate\Support\HtmlString;
class CopyToClipboardAction extends BaseAction
{
"use client";
import {
Dialog,
DialogContent,
DialogTitle,
DialogTrigger
} from "@/components/ui/dialog";
import { cn } from "@/lib/utils";
import { Expand, Loader2, RotateCcw, Trash2, UploadCloud } from "lucide-react";
@dhruva81
dhruva81 / BaseLayout.tsx
Created October 3, 2023 19:20 — forked from mxmtsk/BaseLayout.tsx
React implementation of Vue3 Adapater for https://github.com/lepikhinb/momentum-modal
/**
* Unfortunately I didn't find a way to add it directly to createInertiaApp so
* currently I'm placing it in my BaseLayout which is called on any route anyway
*/
import React from 'react';
import { ModalProvider } from '../components/momentum-modal/ModalContext';
const BaseLayout: React.FC = ({ children }) => {
/* Wrap your children with the provider */
return <ModalProvider resolve={(name) => import(`../pages/${name}`)}>{children}</ModalProvider>;
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@dhruva81
dhruva81 / instructions.md
Created February 17, 2021 11:41 — forked from ju5t/instructions.md
Livewire enabled TinyMCE blade component

Instructions

This is a very basic TinyMCE component. It uses 'entangle'. This allows you to link a Livewire and Alpine property to eachother. If one value changes, the other does too.

Installation

Add tinymce.blade.php to views/components/input. This can be another component folder too if you prefer, but keep in mind that you should also

@dhruva81
dhruva81 / image-src-regexpr.php
Created December 26, 2020 08:51 — forked from vyspiansky/image-src-regexpr.php
PHP: get image src attribute (regular expression)
<?php
// Source: http://goo.gl/qyLFbg
$html = '<img border="0" src="/images/image.jpg" alt="Image" width="100" height="100" />';
preg_match( '@src="([^"]+)"@' , $html, $match );
$src = array_pop($match);
// will return /images/image.jpg
@dhruva81
dhruva81 / blog.md
Created December 22, 2020 16:44 — forked from alesf/blog.md
Laravel - Eloquent: Cascading delete, forceDelete and restore

If you want to delete a model with related models you can use Laravel model events. There is also a special case if your models cascade.

Lets say you have Folder and File Eloquent models that are related and use SoftDeletes trait and when you delete a folder you also want to delete files in folder and all subfolders with files.

In the boot method or Folder model you catch delete and restore events (actually deleting and restoring events that trigger before restoring or deleting happens). You can delete/restore all files in folder you're deleting/restoring with $folder->files()->delete(); and $folder->files()->withTrashed()->restore();.

Folders on the other hand cascade (folder in a folder in a folder) and because events do not trigger if you don't pull the models (->get() method), the model events won't trigger for subfolders. That's why you need to pull the folders and iterate trough them (->each() method) and delete/restore them.

You could use database CASCADE feature but that does