Skip to content

Instantly share code, notes, and snippets.

@anaxamaxan
anaxamaxan / routeNameFromUrl.php
Created October 23, 2023 21:32
Laravel Route Name from URL
<?php
function routeNameFromUrl(string $url, string $method = 'GET'): ?string
{
$method = strtoupper($method);
$request = app('request')
->create(trim($url), $method);
return app('router')
@anaxamaxan
anaxamaxan / carbon_gotcha.php
Last active February 11, 2022 18:07
Carbon gotcha
<?php
use Carbon\Carbon;
Carbon::now()->addDays(365)->diffInDays(Carbon::now());
// 364
Carbon::now()->addDays(365)->diffInDays(Carbon::now()->subSecond());
// 365
@anaxamaxan
anaxamaxan / App\Models\Model.php
Created November 8, 2021 18:47
Laravel Eloquent Model::whereWithHas() global dynamic scope
<?php
namespace App\Models;
use App\Models\Traits\WithWhereHas;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model as BaseEloquentModel;
abstract class Model extends BaseEloquentModel
{
@anaxamaxan
anaxamaxan / gist:df328b21c19fc0c31eb6a455328754a5
Created July 3, 2018 04:54
Plugin loading error: LoadError - cannot load such file -- vagrant/vmware/desktop
vagrant : INFO global: Vagrant version: 2.1.2
At line:1 char:1
+ vagrant up --debug 2>&1 | Tee-Object -FilePath ".\vagrant.log"
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ( INFO global: Vagrant version: 2.1.2:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
INFO global: Ruby version: 2.4.4
INFO global: RubyGems version: 2.6.14.1
@anaxamaxan
anaxamaxan / prepare-commit-msg.sh
Last active November 10, 2017 19:57 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master production dev test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@anaxamaxan
anaxamaxan / gist:4f1d14446945a66e9da500c726a92b01
Created January 27, 2017 21:35
Show/Hide hidden files in Finder
# Add this to your ~/.bash_profile (or .bash_aliases if you have one)
alias showHidden="defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app"
alias hideHidden="defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app"
<?php
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Sa\Http\Controllers\Traits\UsesAccessToken;
use Sa\Models\SupervisionSite;
use Sa\Models\User;
use Sa\Services\AccessToken\AccessToken;
class UsesAccessTokenTest extends TestCase // TestCase extends PHPUnit_Framework_TestCase
{

Keybase proof

I hereby claim:

  • I am anaxamaxan on github.
  • I am anaxamaxan (https://keybase.io/anaxamaxan) on keybase.
  • I have a public key ASCb9EpQic9VzYhJ-snAj_hVAMdTMo3383nUsi6Cmm5ngQo

To claim this, I am signing this object:

@anaxamaxan
anaxamaxan / nightwatch-on-laravel.md
Last active March 24, 2016 02:55
Installing Nightwatch on a Laravel 5.2 project

Here is how I got Nightwatch running on my local machine.

  1. Installed Java 8 JDK. JDK != JRE. I run Mac OS El Capitan. If you type java in the terminal and you get an error like No Java runtime present, requesting install. then you need the JDK. Go to java.com Downloads section and browse to find the latest version of Java SE Development Kit for your system. As of this writing it's version 8.

  2. Install Node and Nightwatch globally. If you don't already have Node, install/Update it via download at https://nodejs.org/. Install nightwatch, preferably globally:

$ sudo npm install -g nightwatch
# in Homestead and typical Ubuntu, put this in /etc/mysql/my.cnf
# right after explicit_defaults_for_timestamp
sql-mode = "ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# Also, if you execute .sql file from an older MySQL version, you might get errors befause the ROW_FORMAT=FIXED is no
# longer a valid option. Search all ROW_FORMAT=FIXED replace with ROW_FORMAT=DYNAMIC