Skip to content

Instantly share code, notes, and snippets.

@gavinhewitt
gavinhewitt / Brand.php
Created April 22, 2021 12:39 — forked from monoman81/Brand.php
Using Filament with Spatie Media Library
//Model Brand.php.
<?php
namespace App\Models\Admin;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\HasMedia;
@gavinhewitt
gavinhewitt / CreateMediaRecord.php
Created April 22, 2021 12:39 — forked from monoman81/CreateMediaRecord.php
Filament Relation Managers and Spatie Media Library
<?php
namespace App\Filament\Resources\Admin\ProductResource\RelationManagers;
use Filament\Resources\RelationManager\CreateRecord;
class CreateMediaRecord extends CreateRecord
{
public function getMediaRealPath()
@gavinhewitt
gavinhewitt / forge.sh
Created October 29, 2019 12:10
Laravel Forge Setup Script
#
# REQUIRES:
# - server (the forge server instance)
# - event (the forge event instance)
# - sudo_password (random password for sudo)
# - db_password (random password for database user)
# - callback (the callback URL)
#
@gavinhewitt
gavinhewitt / README.md
Created May 31, 2018 20:15 — forked from claytonrcarter/README.md
Share named routes between Laravel and Javascript

Share named routes between Laravel and Javascript

This is a 2-part technique to share named routes between Laravel and Javascript. It uses a custom artisan command to export your named routes to JSON, and a Javascript route() helper to lookup the route and fill in any parameters. Written for Laravel 5.3; not tested in 5.4.

Installation

1. Install RouteJson.php

Copy RouteJson.php into your app as app/Console/Commands/RouteJson.php

<?php
// Common Route Patterns http://laravel-tricks.com/tricks/routing-patterns
// Patterns
Route::pattern('id', '\d+');
Route::pattern('hash', '[a-z0-9]+');
Route::pattern('hex', '[a-f0-9]+');
Route::pattern('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}');
Route::pattern('base', '[a-zA-Z0-9]+');
Route::pattern('slug', '[a-z0-9-]+');
Route::pattern('username', '[a-z0-9_-]{3,16}');
@gavinhewitt
gavinhewitt / php_glob
Created August 24, 2016 19:25 — forked from wooki/php_glob
Util function for a recursive filesearch using glob function
/****************************
*
* Util function for a recursive filesearch using glob function
*
****************************/
if ( ! function_exists('glob_recursive')) {
// Does not support flag GLOB_BRACE
function glob_recursive($pattern, $flags = 0) {
@gavinhewitt
gavinhewitt / 0_reuse_code.js
Created July 24, 2014 07:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console