Skip to content

Instantly share code, notes, and snippets.

View LarryBarker's full-sized avatar
🚀

Larry Barker LarryBarker

🚀
View GitHub Profile
@LarryBarker
LarryBarker / CanSeedOncePerDatabase.php
Created September 16, 2024 02:55
The CanSeedOncePerDatabase trait for Laravel projects ensures that database seeders are only executed once per database.
<?php
namespace Database\Seeders;
use Illuminate\Console\View\Components\TwoColumnDetail;
use Illuminate\Support\Facades\DB;
trait CanSeedOncePerDatabase
{
protected string $seedersTable = 'seeders';

Glimpse banner

Glimpse: From Pull to Production, Perfectly.

As software developers one of the key foundations of success is speed and efficiency, especially being a Laravel developer, as you know which is the future of PHP. Before we talk shop, allow me to introduce myself: I’m Larry, a web developer who’s first started learning HTML in the early 90s, eventually picking up PHP (back when header and footer includes were “the way”), and more recently, working with Laravel for close to 7 years now (since version 5.4 / 5.5). My mission is to make web development more approachable, something we all know Laravel excels at.

Let me also introduce you to Glimpse: a tool designed to streamline Laravel development by automatically deploying GitHub pull requests to preview environments. Glimpse not only makes your code review and QA processes easier, but also inc

@LarryBarker
LarryBarker / provision-preview.yaml
Created May 21, 2024 05:19
Automatically deploy PRs to preview environments with the help of Laravel Forge
name: Preview Environment
on:
pull_request:
types: [opened]
env:
FORGE_API_TOKEN: ${{ secrets.FORGE_API_TOKEN }}
FORGE_SERVER_ID: ${{ secrets.FORGE_SERVER_ID }}
@LarryBarker
LarryBarker / input.trigger.js
Created March 18, 2024 03:29
Input Trigger API - This API allows you to change an elements' visibility or status (enabled/disabled) based on another elements' status(es)
/*
* Input Trigger API
* This API allows to change elements' visibility or status (enabled/disabled) basing on other elements' statuses.
* Example: enable a button if any checkbox inside another element is checked.
* - Checked Condition:
<input type="checkbox" id="triggerChk1" />
<button class="btn disabled"
data-trigger-action="enable"
data-trigger="#triggerChk1"
data-trigger-condition="checked">
@LarryBarker
LarryBarker / gist:48e184417b72eedcd5f55cca432de574
Created October 1, 2020 14:42
Determine the next item in an associative array
<?php
$stages = $this->getStages(); // ['foo'=>'bar','bar'=>'foo']
while (key($stages) !== $this->status) {
next($stages); // advance til there's a match
}
return next($stages);
@LarryBarker
LarryBarker / gist:101bf047bf63f64abbc5956821c578a2
Created August 17, 2020 03:47
MySQL lat/lng coordinate search
/**
* Scope locations near a pair of coordinates
*
* @param Builder $query
* @param float $int
* @param float $lng
*/
public function scopeIsNear($query, $lat, $lng)
{
$statement = sprintf("id, name, street, locality, region, postal_code, country, website, phone, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance",
@LarryBarker
LarryBarker / gist:dfbe62eb1bf7787753c69d87b4cfe3ca
Created August 6, 2020 14:01
Custom request object for October-based SPA
export const request = async (handler, data) => {
let response = await fetch('/api', {
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify(data),
cache: 'no-cache',
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json',
'X-OCTOBER-REQUEST-HANDLER': handler,
@LarryBarker
LarryBarker / .env.example
Created August 3, 2020 04:28 — forked from LukeTowers/.0 - cheatsheet.sh
Introduction to OctoberCMS
APP_DEBUG=true
APP_URL=http://example.local
APP_KEY=
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=website-oc-example-LOCAL
DB_USERNAME=homestead
DB_PASSWORD=secret
@LarryBarker
LarryBarker / gist:26a4c66a97dde7479b7ed6551cb75608
Created March 2, 2020 19:16
Streaming Large CSV Files with chunk()
// See: https://medium.com/@barryvdh/streaming-large-csv-files-with-laravel-chunked-queries-4158e484a5a2
/*
* Response
*/
$response = new StreamedResponse(function() {
// Set the file name
$filename = 'claims.csv';
@LarryBarker
LarryBarker / Controller.php
Created October 23, 2019 01:10
AJAX PDF Download
/**
* AJAX handler to generate and return a PDF of the desired report
*
* @param string $shareCode The share code for the report
* @return Response PDF download response
*/
public function view_onDownloadPdf($shareCode)
{
return Backend::redirect("author/plugin/download-pdf/$shareCode");
}