Skip to content

Instantly share code, notes, and snippets.

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

Mahmoud Ahmed (محمود أحمد) m5lil

🏠
Working from home
View GitHub Profile
@m5lil
m5lil / deploy.sh
Created March 2, 2018 23:01
A shell script for setting up Laravel Production environment on Ubuntu 16 system.
#!/usr/bin/env bash
export DEBIAN_FRONTEND=noninteractive
# Check if user is root
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
# Configure
MYSQL_ROOT_PASSWORD="123qweasdzxc"
MYSQL_NORMAL_USER="m5lil"
@m5lil
m5lil / eloquent-cheatsheet.php
Last active October 7, 2018 00:20 — forked from hassansin/eloquent-cheatsheet.php
Laravel 5 Eloquent CheatSheet #laravel #eloquent
Model::
/*Select*/
select('col1','col2')
->select(array('col1','col2'))
->select(DB::raw('businesses.*, COUNT(reviews.id) as no_of_ratings, IFNULL(sum(reviews.score),0) as rating'))
->addSelect('col3','col4')
->distinct() // distinct select
/*From*/
# Apache Server Configs v3.0.0 | MIT License
# https://github.com/h5bp/server-configs-apache
# (!) Using `.htaccess` files slows down Apache, therefore, if you have
# access to the main server configuration file (which is usually called
# `httpd.conf`), you should add this logic there.
#
# https://httpd.apache.org/docs/current/howto/htaccess.html
# ######################################################################
rsync -av -e ssh SOURCE/ USERNAME@NEW_SERVER.COM:/PATH/TO/DESTINATION/
mysqldump --allow-keywords --opt -uMySQL_USERNAME -pPASSWORD DATABASE | ssh USER@DOMAIN "mysql -uMySQL_USERNAME -pPASSWORD DATABASE"
@m5lil
m5lil / Controller.md
Created January 5, 2019 15:40
arabic pdf invoice
//install laravel-dompdf Package and arutil/ar-ph 

public function pdf($id)
{
  $data = Invoice::find($id);
  $pdf = \PDF::loadView('invoice', ['data' => $data]);
  return $pdf->stream('invoice.pdf');
}
@m5lil
m5lil / translate.php
Created January 11, 2019 00:58
scans your project resources/view/ and app/ folder to find lang(...) and __(...) functions, then it create keys based on first parameter value and insert into json translation files
<?php
namespace Translator\Command;
use Illuminate\Console\Command;
class Translator extends Command
{
/**
* @var string
@m5lil
m5lil / redirect.md
Last active January 14, 2019 20:21
redirect to public folder

Method 1

index.php in public_html

<?php
$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}
@m5lil
m5lil / deploying.sh.md
Created January 15, 2019 18:59
Server ssh conf

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

continues...

@m5lil
m5lil / laravel_queryable.md
Last active January 25, 2019 20:57
laravel queryable

I'd suggest something like this:

url/item/?registered=>:DDMMYYYY The parameter name is the name of the attribute Right at the beginning of the parameter value is the operator Operator and value is separated by a : (it actually can be any separation character you want) Other examples:

url/item/?name=like:foo
@m5lil
m5lil / helper.php.md
Created November 8, 2019 23:19
Helper File #laravel #helper
if (! function_exists('home_route')) {
    /**
     * Return the route to the "home" page depending on authentication/authorization status.
     *
     * @return string
     */
    function home_route()
 {