DEV3 Technologies home

Laravel code snippets

Middleware, policies, jobs, services and migrations. 45 free snippets, each with an explanation and usage notes.
45
snippets
2
types

All snippets

Laravel · DatabaseYearly invoice numbering sequenceGap-free invoice numbers such as INV-2026-000042 using one locked counter row per year and prefix, safe under concurrent requests.invoicesequencetransactions Laravel · DatabaseVendor payout ledgerAn append-only ledger where sales, commissions and payouts are signed entries, so a vendor's balance is always a sum and never a stored guess.ledgerpayoutsmarketplace Laravel · UtilitiesvCard download responseBuild an RFC 6350 compliant contact card with escaping and line folding, and return it as a downloadable .vcf file.vcardcontactsdownload Laravel · Queue jobsUptime check job with alert debouncingA queued HTTP monitor check that only raises an alert after several consecutive failures and sends one recovery notice when the site returns.monitoringqueuehttp Laravel · Queue jobsThrottled campaign batch senderSplit a mailing list into chunked queued jobs that respect a per-minute sending cap using Laravel's rate limiter and job batching.emailbatchthrottle Laravel · DatabaseTeam-scoped global scope traitA BelongsToTeam trait that filters every query by the current team and stamps new rows automatically, failing closed when no team is set.multi-tenantglobal-scopeeloquent Laravel · PaymentsStripe Checkout session and verified webhookCreate a hosted Stripe Checkout session over plain HTTP and handle the signed webhook that confirms the payment, with replay protection.stripecheckoutwebhook Laravel · WebhooksSTOP keyword opt-out handling for inbound SMSDetect STOP, UNSUBSCRIBE and START keywords in inbound text messages, update consent atomically and answer with the required confirmation.smsopt-outconsent Laravel · UtilitiesSSL certificate expiry checkerOpen a TLS connection to a host, read the peer certificate and return days remaining, issuer and subject without any extra packages.ssltlsmonitoring Laravel · DatabaseSplit an order per vendorGroup cart lines by vendor, create one sub-order each and share the order discount across them using integer largest-remainder allocation.marketplaceordersdiscount Laravel · NotificationsSMS and WhatsApp driver abstractionSend text messages through one Messenger facade with swappable SMS and WhatsApp drivers, selected by channel name, plus a log driver for local work.smswhatsappdrivers Laravel · UploadsSigned temporary download URLs with a download capHand out expiring signed links for private files and stop serving them after a fixed number of downloads, without exposing storage paths.signed-urldownloadstorage Laravel · UtilitiesSignature capture and PDF stampingValidate a canvas signature sent as a data URL, then stamp it onto a chosen page of an existing PDF at a percentage position.pdfsignaturefpdi Laravel · UtilitiesShort-code generator with collision retryGenerate unambiguous random short codes and rely on the unique index to detect collisions, retrying and growing the length when a space fills up.short-codeuniqueretry Laravel · UtilitiesService-area geofence checkTest whether a latitude and longitude falls inside a stored polygon service area using ray casting, with a bounding-box shortcut.geofencepolygongeojson Laravel · APIsSanctum tokens with abilities and rate limitsIssue scoped personal access tokens with named abilities, enforce them per route, and rate limit API calls per token instead of per IP.sanctumtokensabilities Laravel · UploadsSafe resume upload validationA form request that checks extension, size and real file signature, then stores resumes on a private disk under a random name.uploadvalidationform-request Laravel · MiddlewareReferral attribution cookieCapture a ref code from the URL into a first-party cookie with a validated value and a 30 day window, then read it when the visitor signs up.referralcookieattribution Laravel · PaymentsRecurring donations with Stripe subscriptionsStart a monthly gift as a Stripe Checkout subscription with a custom amount, and record each renewal from the invoice-paid webhook branch.stripesubscriptionrecurring Laravel · Queue jobsQueued click tracking with user-agent filterRedirect instantly and record the click in a queued job, flagging crawlers by user agent so they never inflate your counts.analyticsqueueredirect Laravel · UtilitiesQR code with a centre logoRender a high error-correction SVG QR code and overlay a rounded logo plate in the middle, with no image extension required.qrsvglogo Laravel · MiddlewarePlan-limit gate middlewareRoute middleware that blocks a request when the team has used up its plan allowance for a named limit, with a clear upgrade response.planslimitsmiddleware Laravel · PaymentsPlan-change prorationPure integer maths for mid-cycle upgrades and downgrades: credit unused days of the old plan, charge remaining days of the new one.billingprorationsubscriptions Laravel · PaymentsOne PaymentGateway interface for Stripe, PayPal and RazorpayA small contract plus a Laravel Manager that resolves the active payment gateway from config, so controllers never know which provider runs.paymentsmanagerinterface