Skip to content

Instantly share code, notes, and snippets.

View jwhulette's full-sized avatar
🏠
Working from home

Wes Hulette jwhulette

🏠
Working from home
View GitHub Profile
@jwhulette
jwhulette / Laravel dynamic log path
Last active July 25, 2021 23:00
[Laravel dynamic log path] #php #laravel
$handler = new StreamHandler($path);
$handler->setFormatter(new LineFormatter(null, "Y-m-d H:i:s", true, true));
Log::channel('upkfile')->getLogger()->popHandler();
Log::channel('upkfile')->getLogger()->pushHandler($handler);
@jwhulette
jwhulette / laravel_api.txt
Last active July 27, 2022 13:03
[Larvel to API] Remove items from Laravel to make it API specific #laravel
Remove package.json
Remove webpack.mix.js
Remove /resources
Remove /routes/web.php
Remove welcome.blade.php
Remove api route prefix so that API routes are at the root path
Comment out web middleware in HTTP Kernel
Adjust exception hanlder to always return JSON
@jwhulette
jwhulette / Laravel Custom Rate Limiter
Last active July 27, 2022 13:03
[Laravel Custom Rate Limiter] #php #laravel
<?php
declare(strict_types=1);
namespace App\Traits;
use Closure;
use Illuminate\Cache\RateLimiter;
/**
@jwhulette
jwhulette / php-fpm-settings.txt
Last active July 27, 2022 14:37
[PHP-FPM: Configure Settings] How to set the PHP-FPM servers configuration #php
PHP-FPM: Settings
1. How much memory each PHP FPM process is consuming:
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
2. Server ram:
free -h
Use: https://spot13.com/pmcalculator/
or
@jwhulette
jwhulette / www.conf
Last active July 27, 2022 13:02
[www.conf] A base php-fpm www.conf file #php
; See https://spot13.com/pmcalculator/ for configuration
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[www]
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
@jwhulette
jwhulette / RefreshDatabase.php
Last active December 2, 2022 17:59
[Refresh multiple databases]
<?php
declare(strict_types=1);
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase as FrameworkRefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
trait RefreshDatabase
@jwhulette
jwhulette / snippet.txt
Last active April 25, 2024 19:13
[Change env setting for testing] #PHP #Laravel
app()->detectEnvironment(fn () => 'production');
$this->refreshApplication();
@jwhulette
jwhulette / EnhancedEnum.php
Created September 22, 2022 12:14 — forked from aneesdev/EnhancedEnum.php
EnhancedEnum PHP trait
<?php
trait EnhancedEnum
{
/**
* Get the enum value from the name. e.g case INVOICE = 'invoice'; will return 'invoice'
*
* @param string $name
* @return static
*/
@jwhulette
jwhulette / ForeignKey.php
Last active May 28, 2023 20:50
[Check if foreign key exits] #php #laravel
<?php
declare(strict_types=1);
namespace Database\Helpers;
use Illuminate\Support\Facades\Schema;
class ForeignKey
{
@jwhulette
jwhulette / Column.php
Last active May 28, 2023 20:50
[Check if column exists] #php #laravel
<?php
declare(strict_types=1);
namespace Database\Helpers;
use Illuminate\Support\Facades\Schema;
class Column
{