DEV3 Technologies home

Laravel code snippets, page 2

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

All snippets

Laravel · EmailOne-click unsubscribe with List-Unsubscribe headerAdd RFC 8058 List-Unsubscribe headers to outgoing mail and a signed endpoint that handles the one-click POST from mailbox providers.emailunsubscribeheaders Laravel · DatabaseNearest-rider assignmentFind the closest available courier with a bounding-box prefilter and a haversine distance, then claim them atomically for a delivery.geodispatchhaversine Laravel · DatabaseMonthly usage metering with automatic resetCount usage per team and metric in one row per month, consuming units with a single conditional update so a limit can never be overshot.meteringquotausage Laravel · FormsJSON form schema to validation rulesTurn a stored list of field definitions into Laravel validation rules and attribute names, so user-built forms are validated server side.validationform-builderjson Laravel · WebhooksIdempotent signed webhook receiverAccept webhooks with an HMAC signature and a timestamp window, and process each event id exactly once using a unique-key insert.webhookhmacidempotency Laravel · MiddlewareHoneypot and time-trap middlewareBlock simple form bots with a hidden field and an encrypted render timestamp, rejecting submissions that are filled in too fast.spamhoneypotmiddleware Laravel · MiddlewareEmbed loader with domain allowlistServe a widget script only to pages on approved domains, with wildcard subdomain matching and a frame-ancestors header to match.embedcorsallowlist Laravel · APIsDynamic QR redirect with scan statsA short-code redirect route that looks up a cached destination and counts scans per day with one atomic upsert after the response is sent.redirectanalyticsupsert Laravel · DatabaseTamper-evident document audit trailAppend-only audit events where each row stores a hash of the previous one, with a verify method that detects edited or deleted history.audithash-chaineloquent Laravel · DatabaseDelivery-slot capacity bookingReserve a delivery time slot with a single conditional UPDATE that cannot oversell, plus a matching release when an order is cancelled.bookingcapacityatomic Laravel · APIsCookieless pageview collectorA tracking endpoint that identifies visitors with a daily-rotating salted hash instead of cookies, so no personal data is ever stored.analyticsprivacycookieless Laravel · UploadsChunked upload endpointAccept large files in small indexed parts, store them in a temp folder and assemble them on completion, so uploads survive flaky connections.uploadchunkslarge-files Laravel · NotificationsReverb chat with polling fallbackBroadcast new chat messages over Laravel Reverb and fall back to cursor-based polling when the WebSocket is unavailable.reverbbroadcastwebsocket Laravel · WebhooksBounce and complaint webhook processingTurn provider bounce and spam-complaint events into a suppression list, treating hard bounces at once and soft bounces only after repeats.emailbouncesuppression Laravel · DatabaseBid placement with row lockPlace an auction bid inside a transaction that locks the auction row, validates the minimum increment and updates the leader atomically.auctiontransactionslocking Laravel · UtilitiesAnti-sniping auction extensionExtend an auction's end time when a bid lands in the final minutes, with a cap on total extensions so it cannot run forever.auctiontimingcarbon Laravel · DatabaseAtomic donation goal progressUpdate a campaign's raised total with a single SQL increment and fire a goal-reached event exactly once, even under concurrent donations.donationsatomicprogress Laravel · DatabaseApplicant pipeline state machineA backed enum with an allowed-transitions map and a locked mover that enforces rules, requires a reason for rejection and writes a history row.state-machineenumworkflow Laravel · DatabaseAppend-only points ledgerRecord loyalty points as immutable ledger rows with a running balance, an idempotency key and a locked member row, so totals can always be audited.ledgerloyaltypoints Laravel · APIsAPI resource with sparse fieldsetsLet API clients request only the fields they need with a fields query parameter, applied inside a Laravel JSON resource using a small trait.api-resourcejsonfieldsets Laravel · Queue jobsAffiliate commission jobA queued job that turns a paid order into one commission row with a tiered rate and a hold period, safe against duplicate dispatches.affiliatecommissionqueue