Skip to content

Instantly share code, notes, and snippets.

@mkwsra
mkwsra / Controller.php
Created December 25, 2021 14:40
Laravel - Code snippet - SQL REGEXP search with users full name not only first & last
namespace App\Http\Controllers;
// ....
public static function sanitizeAndPrepareForRegexSearch($searchQuery)
{
// General input sanitization
$sanitized = trim(filter_var($searchQuery, FILTER_SANITIZE_STRING));
// Reserved chars for regex operator
$excludedChars = config('app.excluded_chars'); // ['(', ')', '[', ']', '#', '@', '?', '!', '_', '-', '/', '\\', '^', '~']
@tom2strobl
tom2strobl / pirschFetchClient.ts
Last active November 4, 2021 11:38
basically the pirsch-sdk client, without getters and fetch instead of axios to make it run on an edge / service worker environment
import { IncomingMessage } from 'http'
import { NextRequest } from 'next/server'
import { ClientConfig, AuthenticationResponse, APIError, Hit } from 'pirsch-sdk/types'
const referrerQueryParams = ['ref', 'referer', 'referrer', 'source', 'utm_source']
const defaultBaseURL = 'https://api.pirsch.io'
const defaultTimeout = 5000
const defaultProtocol = 'http'
const authenticationEndpoint = '/api/v1/token'
@fotrino
fotrino / CreateComment.php
Created September 28, 2021 14:35
@mentions with Alpine.js, Livewire & Tributeq
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\User;
class CreateComment extends Component
{
public $mentionables;
@x7ryan
x7ryan / ExampleUsage.php
Last active July 29, 2023 00:03
A simple Laravel Livewire trait to include rules and messages from a Laravel FormRequest Class. Simply use this trait and define a protected property useFormRequest as a reference to the FormRequest class you wish to use. This can be used to share validation logic between livewire components and traditonal Laravel controllers, for example when u…
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Http\Livewire\Concerns\FormRequest;
class ExampleUsage extends Component
{
use FormRequest;
@JustinByrne
JustinByrne / laravel-ci-cd-workflow.yml
Last active May 29, 2024 21:09
Github Action to test laravel and then compile the assets to a production branch
name: CI/CD workflow
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
testing:
<?
//
// AUTO KEYWORD-BASED FOLLOWER CURATION BOT (by @levelsio)
//
// File: twitterFollowerCuratorBot.php
//
// Created: May 2021
// License: MIT
//
@JunaidQadirB
JunaidQadirB / main.yml
Created January 4, 2021 18:23
Github Action to deploy a Laravel App from release tag
name: CD
on:
release:
types:
- released
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@breadthe
breadthe / app%Http%Livewire%Stats%DistanceByYear.php
Last active January 22, 2024 06:26
Laravel Livewire + Apexcharts
<?php
namespace App\Http\Livewire\Stats;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
class DistanceByYear extends Component
{
public $chartId;
@iksaku
iksaku / Sortable.php
Created September 19, 2020 18:31
A helper trait that provides basic PHP compatibility with @livewire's Sortable package
<?php
trait Sortable
{
/**
* This function receives a $newOrder array parameter, which contains the order in which
* we should sort our items after being dragged in the UI. The format of the $newOrder is:
*
* [
* newIndex => [
<?php
namespace App\Charts;
use App\Support\Livewire\ChartComponentData;
use ConsoleTVs\Charts\Classes\Chartjs\Chart;
/**
* Class WanSpeedTestsChart
*