Skip to content

Instantly share code, notes, and snippets.

<?php
namespace App\Entities;
use Illuminate\Database\Eloquent\Model
/**
* Class Contact
* @package App\Entities
*/
// var objectIsDomElement = function (object) {
// return typeof HTMLElement === "object" ? object instanceof HTMLElement :
// typeof object === "object" && object.nodeType === 1 && typeof object.nodeName === "string";
// };
//
// var getAllDomObjects = function() {
// var objs = [];
// var walkTheObject = function (obj) {
// Object.keys(obj).forEach(function (key) {
// var value = objs[key];
@kmuenkel
kmuenkel / AjaxSubmit.js
Last active May 18, 2021 03:43
Apply this 'data-ajax-form' attribute to a Form element, and instantiate this class. That's it.
/**
* @class AjaxSubmit
*/
AjaxSubmit = class
{
/**
* @type {string}
*/
rootUrl = '';
@kmuenkel
kmuenkel / CustomSoftDeletes.php
Last active July 22, 2020 19:52
Customize the nature of the restored and deleted values of a Laravel soft-delete field.
<?php
namespace App\Overrides\Illuminate\Database\Eloquent;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Concerns\HasEvents;
use Illuminate\Database\Eloquent\SoftDeletes as BaseSoftDeletes;
/**
@kmuenkel
kmuenkel / MorphToManyByMany.php
Created July 31, 2020 20:06
Eloquent support for a two-way polymorphic pivot table
class AppServiceProvider
{
/**
* @void
*/
protected function boot()
{
Relation::macro('setMorphTables', function ($foreignPivotTypeField, $relatedPivotTypeField = null) {
/** @var MorphToMany $this */
@kmuenkel
kmuenkel / RedirectByQuery.php
Created July 31, 2020 20:08
Define Laravel routes by query parameters
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use InvalidArgumentException;
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
<?php
namespace App\Helpers;
use Exception;
use ReflectionMethod;
use ReflectionFunction;
use ReflectionException;
/**
@kmuenkel
kmuenkel / MockGuzzleClient.php
Last active September 3, 2020 22:59
Auto-fake Guzzle Responses for Testing
<?php
namespace Tests;
use GuzzleHttp\Client;
use App\Helpers\DebugTrace;
use Illuminate\Support\Arr;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\MockHandler;
use Psr\Http\Message\RequestInterface;
@kmuenkel
kmuenkel / ModerateEvents.php
Created August 28, 2020 18:56
Allow only selected events and/or listeners to fire, for the purposes of testing or logging
<?php
namespace Tests;
use Event;
use Mockery;
use ReflectionFunction;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
@kmuenkel
kmuenkel / SoftRedirect.php
Last active May 7, 2021 14:51
Make sure any custom values applied to the request object past into this class get transposed onto any Controller type-hinted Request objects as well
<?php
namespace App\Http\Middleware;
use Closure;
use Exception;
use RuntimeException;
use ReflectionMethod;
use ReflectionFunction;
use Illuminate\Http\{Request, Response};