Skip to content

Instantly share code, notes, and snippets.

View jzpeepz's full-sized avatar

Jonathan Peoples jzpeepz

  • FLEX360
  • Conway, AR
View GitHub Profile
@jzpeepz
jzpeepz / HasTablePrefix.php
Created December 7, 2020 23:05
Eloquent Table Prefix for Specific Models
trait HasTablePrefix
{
public function getTable()
{
return $this->getPrefix() . parent::getTable();
}
public function setTable($table)
{
if (substr($table, 0, strlen($this->getPrefix())) == $this->getPrefix()) {
elseif (@$data['user_id'] && @$data['only_open'] === true) {
$query = DiscordSupportTickets::where('user_id', '=', $data['user_id'])
->where('open', '=', 1);
->orderBy('ticket', 'DESC')
->get();
}
@jzpeepz
jzpeepz / ActiveSpecialsRelation.php
Last active August 15, 2020 00:57
Complex custom relationship example in Laravel
<?php
namespace App\Relations;
use App\Product;
use App\Special;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\Relation;
@jzpeepz
jzpeepz / reverting-to-a-specific-revision.md
Last active February 24, 2020 20:53
Revert to the specific revision using git reset

Revert to the specific revision using git reset

The solution comes from the Revert to a commit by a SHA hash in Git? question. Here we first hard reset the state of the repository to some previous revision and then soft reset back to current state. The soft reset will keep file modifications, so it will bring old state back on top of the current state:

Careful, reset —hard will remove non-commited changes

$ git reset —hard 0682c06  # Use the SHA1 of the revision you want to revert to HEAD is now at 0682c06 G3
$ git reset —soft HEAD@{1}
$ git commit -m “Reverting to the state of the project at 0682c06”
<?php declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
lambda(function (array $event) {
return 'Hello ' . ($event['name'] ?? 'world');
});
@jzpeepz
jzpeepz / birthdays.php
Last active October 10, 2022 01:46
Get recent/upcoming birthdays in Laravel
<?php
// Note: Adding 1 to the dates below accounts for
// diffences between PHP date('z') [starts at zero]
// and MySQL DAYOFYEAR [starts at 1]
// Want to use specific start and end date?
$start = date('z', strtotime('12/1/2021')) + 1;
$end = date('z', strtotime('1/30/2022')) + 1;
@jzpeepz
jzpeepz / GoogleDoc.php
Created May 28, 2015 16:37
Easy way to pull items from a public Google Doc
<?php
class GoogleDoc {
public function __construct($docId, $sheetId = 1)
{
$this->docId = $docId;
$this->sheetId = $sheetId;
$this->json = file_get_contents('https://spreadsheets.google.com/feeds/list/' . $docId . '/' . $sheetId . '/public/values?alt=json');