Skip to content

Instantly share code, notes, and snippets.

@antonioribeiro
antonioribeiro / php80-buster.dockerfile
Created June 7, 2021 15:31
Laravel Vapor on Debian Buster
FROM php:8.0-fpm-buster
# Install `docker-php-ext-install` helper to ease installation of PHP
# extensions
#
# Ref: https://github.com/mlocati/docker-php-extension-installer
ENV PHP_EXT_INSTALLER_VERSION=1.2.26
RUN set -eux; \
curl --fail -Lo /usr/local/bin/install-php-extensions \
@antonioribeiro
antonioribeiro / gist:6f7a4c9a1336f798fa65
Last active March 9, 2022 05:20
Add more conditions to your Laravel Relations
public function connections()
{
	$relation = $this
		->belongsToMany(static::class, 'connections', 'requestor_id', 'requested_id')
		->withTimestamps();

	/// delete the already built inner join
	$relation
		->getQuery() // Eloquent\Builder
@antonioribeiro
antonioribeiro / gist:24a19f22cffd0beaa7e3
Last active September 13, 2021 19:17
The Laravel Forge, NGINX, PHP-FPM & A Blank Page Debugging Tale

After an apt-get upgrade on my Forge box, both php and nginx got upgraded, and while browsing my sites, PHP FPM was being hit by nginx, but it returned nothing, zilch, nada.

Nothing on laravel.log.

Something in the nginx log:

10.10.10.10 - - [23/Sep/2014:11:52:09 -0300] "GET / HTTP/1.1" 200 31 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"
Blade::extend(function ($view) {
return preg_replace(
'/{{(\'|")(.*)(\'|")}}/',
'<?php echo e(trans($1$2$1)); ?>',
$view
);
});
// And you should be able to do tho this on your Blade templates
@antonioribeiro
antonioribeiro / tables.php
Created October 25, 2016 13:56
Get all tables from database on Laravel
function tables($connection = null)
{
return collect(json_decode(json_encode(DB::connection($connection)->select(get_show_tables_query($connection))), true))
->map(function ($item) {
return array_values($item)[0];
});
}
function get_show_tables_query($connection = null)
{
// in your .env file, split APP_URL to extract protocol and hostname
APP_PROTOCOL=https
APP_HOSTNAME=myapp.test
APP_URL="${APP_PROTOCOL}://${APP_HOSTNAME}"
// install dotenv
npm install dotenv
@antonioribeiro
antonioribeiro / phpx.sh
Created January 23, 2018 19:59
phpx - run php without Xdebug
function phpx {
phpPath=/usr/local/etc/php/$PHP_VERSION
find $phpPath/php.ini $phpPath/conf.d/*.ini ! -name ext-xdebug.ini | xargs cat > $phpPath/php-no-xdebug.ini
php -n -c $phpPath/php-no-xdebug.ini "$@"
}
function in($needle, ...$haystack): bool
{
foreach ($haystack as $hay) {
if ((is_array($hay) && in($needle, ...$hay)) || $needle == $hay) {
return true;
}
}
return false;
}
Route::get('/sign-async-setasign', function () {
// Define the path to the OpenSSL executable
// $opensslPath = 'C:\\OpenSSL-Win32\\bin\\';
$opensslPath = '/usr/bin/';
// require SetaPDF
// require_once 'library/SetaPDF/Autoload.php'; // we are using Composer
date_default_timezone_set('Europe/Berlin');
function clone () {
REPOSITORY=git@github.com:$1.git
echo "Cloning $REPOSITORY using SSH..."
git clone $REPOSITORY $2 2>/dev/null
if [[ $? -ne 0 ]]
then
REPOSITORY=https://github.com/$1.git
echo 'Falling back to HTTPS ($REPOSITORY)...'
git clone $REPOSITORY $2