Skip to content

Instantly share code, notes, and snippets.


Caleb Porzio calebporzio

View GitHub Profile
calebporzio / laracasts_refactoring_to_lookup_tables.php
Created Dec 17, 2019
Laracasts: Refactoring To Lookup Tables
View laracasts_refactoring_to_lookup_tables.php
* Refactor #1:
// Before
if ($user->type === 'admin' || $user->type === 'mod' || $user->type === 'author') {
// Do something.
calebporzio / pure_html_css_modal.css
Last active Feb 28, 2021
The CSS for the pure HTML/CSS modal I tweeted about.
View pure_html_css_modal.css
details summary {
cursor: pointer;
outline: none !important;
display: inline-block;
padding: 8px 12px;
padding-top: 10px;
border-radius: 4px;
overflow: hidden;
background: #F09825;
color: white;
View eloquent_search.php
// Add this to the "boot()" method of your "AppServiceProvider"
\Illuminate\Database\Eloquent\Builder::macro('search', function ($name, $search) {
return $this->where($name, 'LIKE', $search ? '%'.$search.'%' : '');
calebporzio / error_blade_directive.php
Created Mar 28, 2019
A little Blade directive to make working with validation errors a bit nicer.
View error_blade_directive.php
// Usage:
// Before
@if ($errors->has('email'))
<span>{{ $errors->first('email') }}</span>
// After:
View hyper.js
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See for all currently supported options.
module.exports = {
config: {
// Choose either "stable" for receiving highly polished,
// or "canary" for less polished but more frequent updates
updateChannel: 'stable',
calebporzio / webpack.mix.js
Created Mar 2, 2019
A webpack.mix.js file for writing NPM packages the way you write JS in a Laravel app.
View webpack.mix.js
let mix = require('laravel-mix');
mix.js('src/index.js', 'dist/foo.js').sourceMaps();
output: {
libraryTarget: 'umd',
calebporzio / tinker_helper.php
Created Jan 30, 2019
A quick, memorable way to initiate an "artisan tinker" session and play with variables.
View tinker_helper.php
function tinker(...$args) {
// Because there is no way of knowing what variable names
// the caller of this function used with the php run-time,
// we have to get clever. My solution is to peek at the
// stack trace, open up the file that called "tinker()"
// and parse out any variable names, so I can load
// them in the tinker shell and preserve their names.
calebporzio / chain_helper.php
Last active Jul 31, 2019
Handy "chain()" helper method for making non-fluent classes/objects fluent.
View chain_helper.php
function chain($object)
return new class ($object) {
protected $lastReturn = null;
public function __construct($object)
$this->wrapped = $object;
calebporzio / time_travel_helper.php
Last active Aug 18, 2019
A little Laravel helper function for hijacking Carbon's "now()" inside a callback
View time_travel_helper.php
// Helper usage:
// timeTravel(Carbon::parse('one year ago'), function () {...});
function timeTravel($target, $callback) {
return tap($callback(), function () {
calebporzio / VueForm.vue
Created Nov 15, 2018
A Vue component to include Laravel's CSRF Token within form tag
View VueForm.vue
// Usage:
// <vue-form method="PUT">
// <input type="text" name="email">
// <input type="submit">
// </vue-form>
<form :method="method.toUpperCase() == 'GET' ? 'GET' : 'POST'">
<input-hidden :value="csrfToken" name="_token"/>