Skip to content

Instantly share code, notes, and snippets.

View Braunson's full-sized avatar

Braunson Yager Braunson

View GitHub Profile
@Braunson
Braunson / text.md
Created April 12, 2021 15:56
Why Laravel does not provide the authenticated user on any error pages

I was curious why my authenticated user didn't persist to my error pages in Laravel.

Only noticing as the layout used for the error pages (header/footer) is the same as the rest of the site and the top right shows the authenticated user, shows a user nav, logout, etc.

Doing a quick Google search brought up some solutions but not necessarily a reason why authenticated users are not available on the error pages.

The reason not to have the authenticated user on the error page:

  • What if the issue is with fetching the authenticated user?
@Braunson
Braunson / nginx-s3.conf
Created February 24, 2016 22:00 — forked from surjikal/nginx-s3.conf
Nginx - Wildcard subdomains, basic auth and proxying to s3. Set a policy to only allow your server's IP.
server {
listen 80;
server_name *.foo.example.com;
# We need this to resolve the host, because it's a wildcard.
# This is google's DNS server.
resolver 8.8.8.8;
include /etc/nginx/includes/proxy.conf;
@Braunson
Braunson / laravel-renaming-tables-in-production.md
Last active March 25, 2021 21:51
Laravel - Renaming Tables in Production

Laravel - Renaming Tables in Production

So I ran into a use-case where I joined a project that had a prefix on all tables in a production database. Now I couldn't just drop all tables and migrate + seed, this is Production we are talking about!

Since the database had a second (much smaller) app's tables in the same database, I had to be careful that I didn't rename those either.

Here's a quick script I threw in a developer-only route which would generate a query which I could manually run on production at the time of deploying the new code which was stripped of hard coded prefixes. Don't forget when you run this to remove any prefixes set for your connection in config/database.php otherwise you'll have some angry customers and "unable to find table" errors.

@Braunson
Braunson / DirtyOverride.php
Created December 2, 2020 16:16
Laravel - Case your dirty attributes the same way they would be if they were using `getOriginal()`. Add this trait to your app and import it into the model you want to use it with.
<?php
namespace App\Traits;
trait DirtyOverride
{
/**
* Get the attributes that have been changed since last sync.
*
* @return array
@Braunson
Braunson / iseedAll.php
Created June 24, 2020 20:41
Command to use with the iSeed package to get tables, generated the seeds for all tables in one command `php artisan iseed:all`
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class iseedAll extends Command
{
/**
* The name and signature of the console command.
*
@Braunson
Braunson / phpmyadmin.sh
Last active June 24, 2020 19:43
Slightly modified version of https://raw.githubusercontent.com/grrnikos/pma/master/pma.sh to support one argument, the URL to serve the site on.
#!/bin/bash
LATEST_VERSION=$(curl -sS 'https://api.github.com/repos/phpmyadmin/phpmyadmin/releases/latest' | awk -F '"' '/tag_name/{print $4}')
DOWNLOAD_URL="https://api.github.com/repos/phpmyadmin/phpmyadmin/tarball/$LATEST_VERSION"
SERVE_URL=${1:-phpmyadmin.local}
echo "Downloading phpMyAdmin $LATEST_VERSION"
wget $DOWNLOAD_URL -q -O 'phpmyadmin.tar.gz'
mkdir phpmyadmin && tar xf phpmyadmin.tar.gz -C phpmyadmin --strip-components 1
@Braunson
Braunson / gist:9080542
Last active April 11, 2020 15:35 — forked from AstonJ/gist:2896818
Install/Upgrade Ruby on CentOS 6.2 -- Updated ruby to 2.1.0 and yum to 0.1.5
#get root access
$su -
$ cd /tmp
#Remove old Ruby
$ yum remove ruby
# Install dependencies
$ yum groupinstall "Development Tools"
$ yum install zlib zlib-devel
@Braunson
Braunson / CarbonBirthday.php
Last active December 19, 2019 21:04
Carbon macro for checking if a birthday is between two dates (i.e. is the birthday upcoming within the next 3 months)
<?php
// Datermines if the birth date given is between two dates.
Carbon::macro('isBirthdayBetween', function($start, $end) {
// Adjust the birthdate year to the current year
$birthday = $this->copy()->year(date('Y'));
// If the birthday has past, add a year (nearing the new year)
if ($birthday->isPast()) {
$birthday = $birthday->addYear();
@Braunson
Braunson / twitter_favouriter.py
Last active November 17, 2019 06:08 — forked from jmoz/twitter_favouriter.py
Converted to work with Python 3.x
from twitter import Twitter, OAuth, TwitterHTTPError
OAUTH_TOKEN = 'foo'
OAUTH_SECRET = 'bar'
CONSUMER_KEY = 'baz'
CONSUMER_SECRET = 'bat'
t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
@Braunson
Braunson / snippet.php
Last active October 24, 2019 20:40
Laravel Collection Macro trimEndWhile
Collection::macro('trimEndWhile', function ($callback) {
$collection = new static($this->items);
while ($collection->count() && $callback($collection->last()) {
$collection->pop();
}
return $collection;
});