Skip to content

Instantly share code, notes, and snippets.

<?php
namespace App\Support;
use Generator;
class ChunkCsvReader
{
protected array|false $header;
@juampi92
juampi92 / KeyedSession.php
Created December 4, 2022 13:46
KeyedSession
<?php
namespace App\Support;
use Illuminate\Session\Store;
use RuntimeException;
/**
* Helper class that transforms all sessions into a specific key.
*
@juampi92
juampi92 / tests\Support\PrivateAccess.php
Created February 5, 2022 20:54
Testing private methods properties
<?php
namespace Tests\Support;
use ReflectionClass;
use ReflectionException;
use ReflectionObject;
class PrivateAccess
{
@juampi92
juampi92 / Database.php
Created February 1, 2022 18:39
Helper Database::log() to dump query logs. Useful for debugging artisan commands or migrations.
<?php
namespace App\Support;
use Closure;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class Database
{
@juampi92
juampi92 / Str.js
Created July 6, 2021 08:48 — forked from drozdzynski/Str.js
Laravel 5 slug function port to JavaScript
export default class Str {
static slug(value, sep) {
var separator = sep || '-';
value = Str.ascii(value);
var flip = separator == '-' ? '_' : '-';
value = value.replace(new RegExp(Str.pregQuote(flip), 'g'), separator);
@juampi92
juampi92 / RequestBuilder.php
Created November 7, 2019 10:02
Build Requests with routes on Laravel for testing.
<?php
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Route as Router;
class RequestBuilder
{
/**
* Will create a request with the correct fullUrl, route parameters and input parameters.
@juampi92
juampi92 / SafeQueryServiceProvider.php
Last active August 31, 2024 14:22
Database master-slave replication delay in Laravel
<?php
namespace App\Providers;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\ServiceProvider;
class SafeQueryServiceProvider extends ServiceProvider
{
<?php
namespace App\Rules;
use Illuminate\Support\Facades\Validator;
use Illuminate\Contracts\Validation\Rule;
class BaseRule
{
protected $validator = null;
import joi from 'joi'
import validate from 'express-validation'
import middleware from 'middleware'
import AuthService from 'auth.service'
/**
* Controller's generic middleware
*/
export const middleware = [middleware.authenticate('token')]
@juampi92
juampi92 / createSpotifySymLink.bat
Last active March 9, 2018 19:13
Store Spotify downloads in a custom folder using Symbolic Links (Win)