Skip to content

Instantly share code, notes, and snippets.

View sohag-pro's full-sized avatar
:octocat:
Busy with PHP, JS, GO 🐙 Certified Laravel Dev

Sohag Hasan sohag-pro

:octocat:
Busy with PHP, JS, GO 🐙 Certified Laravel Dev
View GitHub Profile
@sohag-pro
sohag-pro / RIB.php
Created March 31, 2021 04:55 — forked from med-ezzairi/RIB.php
A RIB validation rule, could be used with Laravel ^5.5 or separately
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
/**
* RIB validation (valide in morocco only)
*
* @author med-ezzairi
*
@sohag-pro
sohag-pro / deploy.sh
Created May 4, 2021 16:07
Zero Downtime deploy for laravel
#!/bin/bash
# Terminate execution if any command fails
set -e
# Get tag from a script argument
TAG=$1
GIT_REMOTE_URL='here should be a remote url of the repo'
BASE_DIR=/opt/demo
# Create folder structure for releases if necessary
@sohag-pro
sohag-pro / csv-to-sql.php
Created April 12, 2022 06:12
Generate SQL from CSV
<?php
$file = fopen( 'Countries-IT.csv', 'r' );
$csv = [];
while ( ( $line = fgetcsv( $file ) ) !== FALSE ) {
$csv[] = $line;
}
fclose( $file );
print_r( $csv[0] );
@sohag-pro
sohag-pro / ubuntu.sh
Last active September 30, 2023 09:11
Ubuntu usefull commands
# Change Default php version for cli
sudo update-alternatives --config php
# Update composer to V2
sudo composer self-update --2
# Update composer to V1
sudo composer self-update --1
@sohag-pro
sohag-pro / FileService.php
Created September 8, 2022 10:35
File service to easily handle upload and delete files in Laravel
// app/Services/FileService.php
<?php
namespace App\Services;
use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
class FileService {
/**
@sohag-pro
sohag-pro / HasUuid.php
Created September 8, 2022 10:43
UUID helper trait for laravel. Just use it and make migration column type uuid
<?php
namespace App\Traits;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
trait HasUuid {
/**
* Get the value indicating whether the IDs are incrementing.
@sohag-pro
sohag-pro / MakeServiceCommand.php
Created September 8, 2022 10:47
Create "php artisan make:service ExampleService" command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Console\GeneratorCommand;
class MakeServiceCommand extends GeneratorCommand {
/**
* The name and signature of the console command.
@sohag-pro
sohag-pro / csv_to_array.php
Created December 7, 2022 07:04
Read CSV to PHP Array
<?php
$file = fopen( 'file.csv', 'r' );
$csv = [];
while ( ( $row = fgetcsv( $file ) ) !== FALSE ) {
$csv[] = array_map( function ( $value ) {
return preg_replace(
['/"/', "/\r?\n/", '/[\x00-\x1F\x80-\xFF]/'],
['""', '<br>', ''],
$value
@sohag-pro
sohag-pro / laravelTesting.sh
Created December 22, 2022 08:21
Laravel Testing Commands and Tips
# testing env
.env.testing
# In memory sqlite db
DB_CONNECTION=sqlite
DB_DATABASE=:memory: # in memory sqlite db
# Look for some text
$this->assertSee('text');
@sohag-pro
sohag-pro / docker-compose.yml
Last active July 3, 2023 09:54
Laravel SAIL with PHPMyAdmin
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts: