[Compare] Berbedaan dan Perbandingan Flutter vs React Native

flutter vs react native

2017 Dunia Coding di hebohkan dengan rilisnya bahasa baru dari google. Bahasa untuk men-develop aplikasi mobile multi platform Android dan IOS. FLUTTER ikut meramaikan kancah persaingan antar bahasa pemrograman di platform mobile device. Dengan sekali coding hasilnya dapat berjalan di android dan IOS.
Tentu setiap framework mempunyai kelebihan dan kekurangan masing-masing. Pada ulasan kali ini kita bahas tentang Flutter dan React Native yang notabene sedang popular dan banyak dipakai.

1. Vendor Developer

Seperti yang kita tahu bersama bahwa 2 framework ini di develop oleh 2 raksasa yakni Flutter oleh Google dan React Native oleh Facebook. Sangat menjanjikan.

2. Initial Release

React Native rilis tahun 2015 otomatikeli dia lebih tua dan sewajarnya lebih banyak pengalaman nya. Sedangkan Flutter 2017, walaupun baru kemaren namun perkembangan nya bisa dibilang pesat.

3. Language

Javascript adalah bahasa yang dipakai React Native. Ini menjadi poin plus tersendiri karena javascript sudah dikenal sejak lama dan banyak yang menguasai sehingga tidak membutuhkan waktu lama dalam mempelajarinya. Sedangkan Flutter menggunakan Dart, bahasa baru yang mudah digunakan bagi developer yang terbiasa dengan OOP seperti C++ dan Java.

4. Learning Curve

React Native sepertinya mendapat poin plus untuk ini karena menggunakan javascript sebagai base nya.

5. Platform

Sama2 multi platform. draw

6. Simulator

Sama2 punya hot reload yang memungkinkan untuk live coding melihat hasil nya.

7. Reusable Code

Flutter membuat developer menjadi mudah karena dapat melakukan reuse existing code. Sedangkan pada React Native meskipun dapat reusable code namun lebih mudah di Flutter

8. Code Style

Flutter dikenal dengan simplicity nya. Sedangkan React Native dikenal dengan Ready to Use componen nya.

9. Development Time

Tergantung developer, Flutter dengan simplicity dan reuse code nya. React Native dengan ready to use library nya.

10. Stability

Karena Flutter lahirnya kalah cepet ya wajar kalo React Native lebih stabil.

11. Performance

Nah, Flutter ini direct component to device loo. Sedangkan React Native pake layer javascript.

12. Library

Sama sama Banyak

13. Time to Reach Market

Tergantung developer juga. Flutter cocok buat  prototyping. React Native cocok buat longterm karena lebih stabil dan mature

14. Popularity

Otomatis React Native lebih populer wong lahir duluan. Namun Flutter sudah hampir menyusul loo.

15. Community

Kalo sekarang banyakan React Native

16. Documentation

Flutter Rapi dan update jadi bagi developer pemula mudah belajar. Sedangkan react kurang terorganisir tapi up to date.

17. Used By

Sama sama dipakai perusahaan-perusahaan besar.

Berikut ringkasan komparasi dari 2 jawara mobile apps builder framework.

Flutter83Faktor87React Native
Google
5
Developers
5
Facebook
2017
4
Initial Release
6
2015
Dart
5
Language
5
JavaScript
Need learning Dart
4
Learning Curve
6
Famous Javascript
Android and iOS
5
Platform
5
Android and iOS
Stateful Hot Reload
5
Simulator
5
Hot Reload
Yes
6
Reusable Code
4
Reuse but restrict few component
Simplicity
6
Code Style
4
More Strict
More time, but reusable code
4
Dev Time
6
Ready to use component
Trying to Stable
4
Stability
6
Mature, older
Direct with native component
6
Performance
4
Use Javascript Layer
Many
5
Library
5
Many
Fast, Cocok untuk protitype
5
Time to Reach Market
5
Longterm lebih matur
60k github
4
Popularity
6
76k github
fast growt
4
Community
6
Large already
Rapi dan up to date
6
Documentation
4
Kurang rapi tapi up to date
Alibaba, Reflectly, Tencent, Hamilton Musical, Google Greentea, JD Finance, Abbey Road Studios, etc
5
Used By
5
Facebook, Oculus Go VR Headset, Instagram, Pinterest, Uber, Tesla, Walmart, Wix.com, Baidu, Artsy, etc

referensi :

[solved] convert htaccess apache to nginx wordpress rewrite rule

convert htaccess to nginx

convert htaccess apache to nginx

Saya baru migrasi dari apache2 ke nginx. Saya bingung bagaimana rewrite rules untuk wordpress di nginx ?
Berikut ini adalah htaccess saya sebelumnya…

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

 

Jawaban


  1. open/buka nginx.conf di /etx/nginx/nginx.conf
    vi /etx/nginx/nginx.conf
  2. edit atau tambahkan barus seperti berikut, sesuaikan pathnya
    server {
      ..
      ..
    
      location /blog {
          try_files $uri $uri/ /blog/index.php?$args;
      }
    
      location ~ \.php$ {
          fastcgi_split_path_info ^(/blog)(/.*)$;
      }
    
      ..
      ..
    }

    asumsi wordpress punya subdirectory blog

lihat juga cara redirect dengan nginx disini
ada juga tool online untuk konversi disini

About the htaccess to nginx converter winginx.com
The service is to convert an Apache’s .htaccess to nginx configuration instructions. First of all, the service was thought as a mod_rewrite to nginx converter. However, it allows you to convert some other instructions that have reason to be ported from Apache to nginx. Note server instructions (e.g. php_value, etc.) are ignored. The converter does not check syntax, including regular expressions and logic errors. Please, check the result manually before use.

I’m having no luck converting htaccess rules to nginx rewrite. I’ve checked out the NginxRewriteModule documentation and have a few done, but the more complicate ones I’m at a loss for. Here’s what I’m looking at:

DevOps Expert | Haproxy – Instalasi & Konfigurasi pada VPS Ubuntu 18.04

haproxy load balancer server

Pada bab sebelumnya kita sudah mengetahui tentang apa, mengapa dan bagaimana cara kerja haproxy. Jika Anda belum mengetahui konsep dan alasan di balik haproxy sebaiknya Anda membacanya terlebih dahulu disini.

Haproxy Installation

Pertama kita create vps terlebih dahulu, bisa dengan digital ocean atau vultr atau yang lain nya. Jika belum mengetahui cara deploy (membuat) VPS dan instalasinya silahkan ikuti step by step disini. Selain VPS bisa juga menggunakan VM (virtual machine) atau bahkan dedicated computer.

Sediakan 3 VPS. Saya asumsikan sudah terinstall ubuntu server 18.04 atau keluarga debian, karena kurang lebih caranya sama kalau sesama keluarga linux debian. beda-beda dikit paling.
Pada VPS 1 (Hostname haproxy.qodrbee.com) lakukan

  1. Setting IP private
    edit file konfigurasi ip address

    root@haproxy:~# nano /etc/netplan/01-netcfg.yaml

    akan muncul isi file seperti ini lalu edit ip address menjadi 192.168.1.1/24

    network:
      version: 2
      renderer: networkd
      ethernets:
        ens3:
          dhcp4: yes
        ens7:
          addresses: [192.168.1.1/24]
          dhcp4: no
          dhcp6: no
          optional: true
          nameservers:
            addresses: [8.8.8.8,8.8.4.4]
    

    ens3 adalah ethernet yg terhubung ke public dan
    ens7 adalah yang terhubung ke private atau ke web server kita nantinya.
    Angka 3 dan 7 pada ens bisa berbeda untuk vps lain. Silahkan disesuaikan
    jika sudah simpan dengan ctrl+x lalu apply settingan tersebut dengan perintah

    root@haproxy:~# netplan apply

    cek ip address ens7 apakah sudah berubah

    root@haproxy:~# ifconfig
    ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 10.20.30.40  netmask 255.255.254.0  broadcast 10.20.30.255
            inet6 fe80::5400:1ff:fef4:c42e  prefixlen 64  scopeid 0x20<link>
            ether 56:00:01:f4:c4:ce  txqueuelen 1000  (Ethernet)
            RX packets 2008493  bytes 468728324 (468.7 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 1952526  bytes 1666990785 (1.6 GB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ens7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.1  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::5800:1ff:fef4:c48e  prefixlen 64  scopeid 0x20<link>
            ether 5a:00:01:f4:c4:ce  txqueuelen 1000  (Ethernet)
            RX packets 8122671  bytes 2208780819 (2.2 GB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 14258789  bytes 1377041568 (1.3 GB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 104578  bytes 9203032 (9.2 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 104578  bytes 9203032 (9.2 MB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
  2. Install haproxy
    update repo

    root@haproxy:~# apt update

    install haproxy

    root@haproxy:~# apt install haproxy

    Setelah terinstall, maka edit default config aplikasi haproxynya untuk mengarahkan settingan load balancernya, di /etc/default/haproxy , hilangkan tanda # di awal tulisan CONFIG dan ubah ENABLED menjadi 1.

    root@haproxy:~# nano /etc/default/haproxy
    # Defaults file for HAProxy
    #
    # This is sourced by both, the initscript and the systemd unit file, so do not
    # treat it as a shell script fragment.
    
    # Change the config file location if needed
    CONFIG="/etc/haproxy/haproxy.cfg"
    
    # Add extra flags here, see haproxy(1) for a few options
    #EXTRAOPTS="-de -m 16"
    ENABLED=1

    okey sekarang installasi haproxy sudah selesai, nanti kita lanjutkan untuk konfigurasinya.

Kemudian pada VPS 2 dan 3 (web1.qodrbee.com dan web2.qodrbee.com) kita lakukan

 

Haproxy Configuration

buka file konfigurasi haproxy

root@haproxy:~# nano /etc/haproxy/haproxy.cfg
global
    log 127.0.0.1 local0 notice   # menyimpan log pada 
                                  # syslog server (localhost)
    maxconn 2000          # max koneksi yang ditangani secara bersamaan
    user haproxy          # user yg menangani haproxy (jgn diganti)
    group haproxy         # group yg menangani haproxy (jgn diganti)

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3             # jml percobaan ketika timeout sebelum failure
    option redispatch     # meng-enable session redistribution 
                          # jika connection fail
    timeout connect  5s   # lama max sampai terhubung ke server 
                          # hingga berhasil
    timeout client  10s   # lama proses pengiriman data client/server
    timeout server  10s   # lama proses pengiriman data client/server

    listen web-load-balanced 0.0.0.0:80 # listen agar dapat di akses 
                                        # dari manapun
    mode http
    balance roundrobin    # algoritma metode load balancing
                          # ada pilihan algoritma roundrobin/static-rr/
                          # leastconn/source/uri/url_param
    option httpclose
    option forwardfor
    server web1 192.168.1.2:80 check # server backend, health check untuk 
    server web2 192.168.1.3:80 check # mengetahui status server backend

Oke konfigurasi standar haproxy sudah selasai. Selanjutnya kita uji coba. Start dulu haproxynya

root@haproxy:~# service haproxy start

buka komputer lain di luar VPS untuk melakukan request ke server load balancer sebut saja komputer user. Misal kita kasih IP address nya 192.168.1.111
kita lakukan dengan browser atau curl. Untuk uji coba kali ini kita pakai curl.
buat script php sebagai berikut untuk mengetahui IP server dan Client dari request.
simpan di /var/www/html/cek_loadbalance.php di server web1 dan web2

<?php
header('Content-Type: text/plain');
echo "Server IP: ".$_SERVER['SERVER_ADDR'];
echo "\nClient IP: ".$_SERVER['REMOTE_ADDR'];
echo "\nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];
?>

lalu dari komputer user lakukan

root@user:~# curl cek_loadbalance.php

seharusnya akan muncul hasil seperti ini

root@user:~$ curl http://192.168.1.1/cek_loadbalance.php
Server IP: 192.168.1.2
Client IP: 192.168.1.1
X-Forwarded-for: 192.168.1.111
root@user:~$ curl http://192.168.1.1/cek_loadbalance.php
Server IP: 192.168.1.3
Client IP: 192.168.1.1
X-Forwarded-for: 192.168.1.111

perhatikan server IP… dia berganti ganti karena kita memakai algoritma round robin. Request yang datang ke load balancer di arahkan bergantian ke 192.168.1.2 (web1) dan 192.168.1.3(web2)

X-Forwarded-for adalah IP komputer user

[tutorial] Install XAMPP untuk Local Server pada Windows

Pada kesempatan ini kita akan melakukan instalasi web server dan database server mysql yang di bundling dalam XAMPP. berikut langkah-langkahnya

  1. Download XAMPP dari https://www.apachefriends.org
  2. Install XAMPP
  3. Konfigurasi XAMPP

Mari kita jabarkan tiap poinnya

1. Download XAMPP

Silahkan pilih versi yang akan di download. Pastikan bahwa versi yang dipilih mendukung aplikasi yang akan kita bangun. Selain itu sesuaikan juga OS yang digunakan. Dalam tutorial ini kita install di OS windows. Kali ini kita pilih download versi 7.2.17

 

tunggu sampai download selesai. Jika sudah jalankan file tersebut untuk mulai proses instalasi.

2. Instalasi XAMPP

Jalankan file tersebut dengan doublie klik atau tekan enter.

 

Pilih lokasi directory tempat file-file akan di install. Misal kita pilih D:\xampp
klik next > next > finish. Selanjutnya jalankan file

3. Konfigurasi

Konfigurasi ini tergantung keperluan

 

tes12

[tutorial] BAB 1 Persiapan CRUD pada Framework Laravel dan VueJS

crud laravel vuejs

Persiapan

Setelah kita mulai mempelajari suatu bahasa pemrograman tentang konsep, fundamental dan basic nya maka saatnya kita praktek lebih dalam praktek teknis pembuatan aplikasi yang sederhana. Suatu aplikasi hampir dipastikan ada aksi-aksi seperti

  • Create – menambah data
  • Read – membaca dan menampilkan data
  • Update – meng-edit dan update data
  • Delete – menghapus data

Aksi-aksi tersebut sering dan sudah biasa disebut dengan CRUD. Namun kali ini kita akan belajar praktek dari 0 (from scratch) membuat CRUD plus dengan Search, Pagination dan Report (laporan).

Teknologi yang akan kita pelajari dan praktekan diantaranya adalah

  • Xampp – Bundling Web server (apache2), DB server (Mysql) di local komputer kita
  • Composer – package manager
  • Framework Laravel – easily and quickly PHP framework based on MVC design pattern
  • Blade Template Engine – default bawaan laravel
  • Mysql Database – database sejuta umat
  • Framework VueJS – framework JS
  • Vue Router – agar vueJS lebih mudah
  • Axios – untuk menghadle http request
  • Ajax Request – agar http request lebih nyaman dan cepat
  • Html Form, table dll – view html

Kita asumsikan OS yang dipakai adalah windows. Pada tahap persiapan ini yang perlu kita lakukan diantaranya adalah

  1. Instalasi Xampp
  2. Instalasi Composer
  3. Instalasi Laravel
  4. Integrasi VueJS
  5. Menyusun relasi database

karena kita mau menggunakan laravel maka kita perlu ketahui dulu requirement dari versi laravel yang akan kita install. Kita akan menggunakan laravel versi 5.7.
Update fitur laravel versi 5.7 diantaranya

  • Securing Laravel APIs with Auth0
  • Laravel Dump Server Integration
  • Laravel Nova
  • Guest User Gates / Policies
  • Email Verification
  • Optional Email Verification
  • URL Generator & Callable Syntax
  • Paginator
  • Improved Error Messages
  • Testing Artisan Commands

kemudian requirement untuk laravel 5.7 adalah

  • PHP >= 7.1.3
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • BCMath PHP Extension

1. Instalasi XAMPP

Setelah kita mengetahui requirement Laravel maka kita perlu memilih versi Xampp yang mendukung requirement tersebut. Kita pilih xampp versi 7.2.17.
untuk detail tahap ini kita lanjutkan di sub bab berikutnya yakni installasi xampp di link ini

[tutorial] Analisa simple Log HaProxy dengan halog

haproxy load balancer server

How To Analyze HaProxy Logs

HALog adalah tool simple namun powerful untuk menganalisa HaProxy log. yuk lets try…

  1. Instalasi

    cd /usr/src
    wget http://haproxy.1wt.eu/download/1.5/src/devel/haproxy-1.5-dev11.tar.gz
    tar xzf haproxy-1.5-dev11.tar.gz
    cd haproxy-1.5-dev11/contrib/halog
    make
    cp halog /usr/bin/
  2. Get number of requests treated by the server (columns “tot_req”)

    cat /var/log/haproxy.log | halog -srv -H -q |awk 'NR==1; NR > 1 {print $0 | "sort -n -r -k 9"}' |column -t
  3. List servers by response time in milisecond (columns “avg_rt”)

    cat /var/log/haproxy.log | halog -srv -H -q |awk 'NR==1; NR > 1 {print $0 | "sort -n -r -k 12"}' |column -t
    
  4. List servers by application errors: HTTP status code 5xx (column “5xx”)

    cat /var/log/haproxy.log |halog -srv -H -q | awk 'NR==1; NR > 1 {print $0 | "sort -n -r -k 6"}' | column -t
    
  5. List servers errors related by application (prefixed by the backend name)

    cat /var/log/haproxy.log |halog -srv -H -q | awk 'NR==1; NR > 1 {print $0 | "sort -n -r -k 5"}' | column -t
    
  6. List URLs by server computation time in milliseconds (column “okavg”)

    cat /var/log/haproxy.log | halog -ut -H -q | column -t
    
  7. List URLs by errors (column “err”)

    cat /var/log/haproxy.log | halog -ue -H -q | column -t
    
  8. List URLs by missing files: HTTP status code 404 (column “req”)

    cat /var/log/haproxy.log | halog -u -H -q -hs 404 | column -t
    
  9. List URLs by number of request(column “req”)

    cat /var/log/haproxy.log | halog -u -H -q | awk 'NR==1; NR > 1 {print $0 | "sort -n -r -k 1"}' | column -t
    

Jangan lupa sesuaikan path log haproxy nya.
untuk cara install dan setting haproxy sendiri ada disini

referensi : https://haproxy-log-analyzer.readthedocs.io/

[tutorial] bagaimana melakukan redirect di nginx

redirect di nginx

Kapan kita melakukan redirect?

Ketika anda punya broken link yang ingin supaya link nya dapat dipakai lagi, semisal karena sudah terindex oleh google. Bisa juga karena web anda sedang maintenance sementara sehingga redirect kehalaman maintenance agar pengunjung dapat info.
Okey… disini saya anggap temen2 sudah tau apa itu file htaccess, karena kita akan langsung kepada intinya. Bagi yang belum mengetahui tentang htaccess bisa baca-baca disini.

Bagaimana caranya?

untuk melakukan redirect di nginx bisa kita lakukan dengan meng-edit file konfigurasi di nginx atau di konfigurasi domain nginx.

  1. pake return (example : return 301 https://example.com$request_uri;)
    server {
        listen 80;
        listen [::]:80;
        hostname example.com www.example.com;
        return 301 https://example.com$request_uri;
    }
  2. pake regex (example : rewrite ^/foo/(bar)/(.*)$ https://$server_name/$1/$2 permanent; )
    server {
        listen 80;
        listen [::]:80;
        hostname example.com www.example.com;
        root /var/www/example.com/public;
        rewrite ^/foo/(bar)/(.*)$ $scheme://$server_name/$1/$2 permanent;
    }
  3. pake map
    include redirect-map.conf;
    server {
        […]
        if ( $redirect_uri ) {
            return 301 $redirect_uri;
        }
    }

    redirect-map.conf isinya …

    map $request_uri $redirect_uri {
        /home.html          /beranda;
        /usman.html         /cakep;
        /ribuantoro.html    /ganteng;
    }
  4. HTTP to HTTPS
    return 301 https://$host$request_uri;
  5. non-www to www
    if ( $host !~ ^www\. ) {
        return 301 $scheme://www.$host$request_uri;
    }
  6. www to non-www
    if ( $host ~ ^www\.(?<domain>.+)$ ) {
        return 301 $scheme://$domain$request_uri;
    }

     

Selain redirect di nginx bisa juga redirect dengan file htaccess namun menggunakan webserver apache. berikut caranya disini
Semoga bermanfaat.

referensi :
nginx official

[compare] Perbedaan dan perbandingan WebSocket vs Socket.io

WebSocket vs socket.io

Apa perbedaan websocket dengan socket.io

Oke pertama kita bahas dulu tentang websocket.
Websocket adalah Protokol komunikasi yang menyediakan komunikasi dua arah antara Klien dan Server melalui koneksi TCP, WebSocket selalu open sepanjang waktu sehingga mereka memungkinkan transfer data real-time.
Ketika klien melakukan request ke Server, koneksi tidak tertutup (closed) saat response diterima, koneksi akan tetap open sampai klien atau server mengakhiri request.

Poin penting pada websocket diantaranya

  • WebSocket membantu komunikasi realtime antara client dan web server.
  • WebSocket membantu komunikasi cross-platform antara client dan web server.
  • WebSocket membantu kebutuhan bisnis di seluruh dunia untuk realtime web aplikasi.
  • WebSocket membantu koneksi pada HTTP dalam komunikasi full duplex
  • WebSocket menghilangkan overhead and mengurangi complexity.
  • WebSocket membuat komunikasi real-time lebih mudah dan efisien.

Skema Protokol WebSocket :

WebSocket vs socket.io

Selanjutnya kita lihat tentang Socket.io
Socket.io adalah library yang memungkinkan komunikasi real-time dan full dupleks antara Klien dan server Web. Ia menggunakan protokol WebSocket sebagai interface nya. Secara umum socket.io dibagi menjadi dua bagian yakni sisi client berupa library yang berjalan di browser dan sisi server berjalan di web server.

Poin penting pada socket.io diantaranya

  • Socket.io dapat melakukan broadcast ke beberapa socket sekaligus dan dapat menangani koneksi secara transparan.
  • Socket.io bekerja di semua platform, server atau device dan meningkatkan kualitas, keandalan, dan kecepatan.
  • Secara otomatis meningkatkan requirement ke WebSocket jika diperlukan.
  • Socket.io mengimplementasikan real-time transport protocol real-time secara custom dibanding protokol lainnya.
  • Socket.io membutuhkan dua library untuk digunakan sisi Klien dan library sisi server.
  • Socket.io berjalan dengan work-based event. ada beberapa event khusus yang dapat diakses menggunakan Socket di sisi server seperti Connect, message, Disconnect, Ping dan Reconnect.
  • Ada beberapa event yang dijalankan khusus oleh Klien seperti Connect, connect- error, connect-timeout and Reconnect
  • Secara teknis Socket.io menangani komunikasi full dupleks secara real time.
  • Socket.io juga menangani ketidakkonsistenan dari browser.
  • Socket.io juga memberikan dukungan fitur tambahan untuk infrastruktur publikasi dasar dan melakukan reconnect secara otomatis.
  • Saat ini, AFAIK adalah yang paling sering digunakan dan lebih mudah untuk membantu dalam pengembangan vanilla web soket.

Websocket VS Socket.io

mari kita lihat perbedaan nya dalam table perbandingan

No.WebSocketSocket.io
1protocol yang tebangun pada koneksi TCPlibrary untuk berjalan dengan WebSocket
2full duplex communication pada koneksi TCPkomunikasi event-based antara browser dan server.
3Proxy dan load balancer tidak didukung di WebSocket.koneksi dapat terbangun walaupun lewat proxi and load balancer.
4.tidak support broadcasting.supports broadcasting.
5.tidak punya a fallback option.supports fallback options.

Kesimpulan nya

Untuk kebutuhan realtime communication socket.io melengkapi websocket dalam praktek pengembangan aplikasinya. Untuk lebih jelasnya silahkan praktekan secara teknis penggunaannya.

referensi : https://educba.com

[tutorial] install free cpanel vps dengan centos web panel (CWP)

install cwp centos web panel

Bismillah – Assalamualaikum wa rohmatullohi wabarokatuh

Bagi temen-temen yang baru migrasi dari shared hosting ke vps tentu agak kaget dalam config web ketika sebelumnya tinggal klik klik dengan cpanel yang memanjakan tiba-tiba berubah menjadi layar hitam dengan text putih manual ngetik command2 bak hacker legendaris mau meretas situs pemerintahan … #eh

sebenarnya banyak sesuatu seperti cpanel hosting dalam mengelola vps bahkan cpanel free alias cpanel gratis atau web panel gratis. yang kita perlukan hanya cara install dan cara pakai nya, salah satu nya adalah CWP atau kepanjangan dari centos web panel.

namanya aja centos berarti ini panel yang berjalan di atas OS linux centos, maka wajib bagi anda install vps dengan OS centos dan minimal centos 6 ya… siip asumsi anda sudah bisa atau mahir dan terbukti sudah menginstall centos di vps anda, bisa di digital ocean atau vultr atau yang lain nya… 

 

Berikut Step by step install centos web panel (CWP) 

  1. download dan install (sekitar 30 menitan)

    cd /usr/local/src
    wget http://centos-webpanel.com/cwp-latest
    sh cwp-latest
    
    jika download link gagal ganti dengan :
    CentOS 6: http://dl1.centos-webpanel.com/files/cwp2-latest
    CentOS 7: http://dl1.centos-webpanel.com/files/cwp-el7-latest
  2. reboot server (agar update)

    reboot
  3. Konfigurasi

    Log in to your CWP server CentOS WebPanel Admin GUI lewat browser
    http://SERVER-IP:2030/
    Username: root
    Password: your root password 
    – Setup nameservers 
    – Setup shared ip (harus IP public anda) 
    – Setup paling tidak 1 hosting paket (atau edit default package) 
    – Setup root email 

    konfigurasi lain nya bisa cek di http://wiki.centos-webpanel.com/
  4. Bingung ?

    Kontak WA 08975835238 atau email ke ztoro@qodrbee.com untuk training.

[tutorial] Bab 9 Cheatsheet Laravel 5.1

Laravel-Cheat-Sheet

Artisan

// Added in 5.1.11:http://laravel.com/docs/5.1/authorization#creating-policies
php artisan make:policy PostPolicy
// Displays help for a given command
php artisan --help OR -h
// Do not output any message
php artisan --quiet OR -q
// Display this application version
php artisan --version OR -V
// Do not ask any interactive question
php artisan --no-interaction OR -n
// Force ANSI output
php artisan --ansi
// Disable ANSI output
php artisan --no-ansi
// The environment the command should run under
php artisan --env
// -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
php artisan --verbose
// Remove the compiled class file
php artisan clear-compiled
// Display the current framework environment
php artisan env
// Displays help for a command
php artisan help
// Lists commands
php artisan list
// Interact with your application
php artisan tinker
// Put the application into maintenance mode
php artisan down
// Bring the application out of maintenance mode
php artisan up
// Optimize the framework for better performance
// --force    Force the compiled class file to be written.
// --psr      Do not optimize Composer dump-autoload.
php artisan optimize [--force] [--psr]
// Serve the application on the PHP development server
php artisan serve
// Change the default port
php artisan serve --port 8080
// Get it to work outside localhost
php artisan serve --host 0.0.0.0
// Set the application namespace
php artisan app:name namespace
// Flush expired password reset tokens
php artisan auth:clear-resets
// Flush the application cache
php artisan cache:clear
// Create a migration for the cache database table
php artisan cache:table
// Create a cache file for faster configuration loading
php artisan config:cache
// Remove the configuration cache file
php artisan config:clear
// In program
$exitCode = Artisan::call('config:cache');
// Seed the database with records
// --class      The class name of the root seeder (default: "DatabaseSeeder")
// --database   The database connection to seed
// --force      Force the operation to run when in production.
php artisan db:seed [--class[="..."]] [--database[="..."]] [--force]

// Generate the missing events and handlers based on registration
php artisan event:generate

// Create a new command handler class
// --command      The command class the handler handles.
php artisan handler:command [--command="..."] name
// Create a new event handler class
// --event        The event class the handler handles.
// --queued       Indicates the event handler should be queued.
php artisan handler:event [--event="..."] [--queued] name

// Set the application key
php artisan key:generate

// By default, this creates a self-handling command that isn't pushed to the queue.
// Pass this the --handler flag to generate a handler, and the --queued flag to make it queued.
php artisan make:command [--handler] [--queued] name
// Create a new Artisan command
//  --command     The terminal command that should be assigned. (default: "command:name")
make:console [--command[="..."]] name
// Create a new resourceful controller
// --plain      Generate an empty controller class.
php artisan make:controller [--plain] name
php artisan make:controller App\Admin\Http\Controllers\DashboardController
// Create a new event class
php artisan make:event name
// Create a new middleware class
php artisan make:middleware name
// Create a new migration file
// --create     The table to be created.
// --table      The table to migrate.
php artisan make:migration [--create[="..."]] [--table[="..."]] name
// Create a new Eloquent model class
php artisan make:model name
// Create a new service provider class
php artisan make:provider name
// Create a new form request class
php artisan make:request name
// Database migrations
// --database   The database connection to use.
// --force      Force the operation to run when in production.
// --path       The path of migrations files to be executed.
// --pretend    Dump the SQL queries that would be run.
// --seed       Indicates if the seed task should be re-run.
php artisan migrate [--database[="..."]] [--force] [--path[="..."]] [--pretend] [--seed]
// Create the migration repository
php artisan migrate:install [--database[="..."]]
// Create a new migration file
// --seeder     The class name of the root seeder.
php artisan migrate:refresh [--database[="..."]] [--force] [--seed] [--seeder[="..."]]
// Rollback all database migrations
// --pretend    Dump the SQL queries that would be run.
php artisan migrate:reset [--database[="..."]] [--force] [--pretend]
// Rollback the last database migration
php artisan migrate:rollback [--database[="..."]] [--force] [--pretend]
// Show a list of migrations up/down
php artisan migrate:status
// Create a migration for the queue jobs database table
php artisan queue:table
// Listen to a given queue
// --queue      The queue to listen on
// --delay      Amount of time to delay failed jobs (default: 0)
// --memory     The memory limit in megabytes (default: 128)
// --timeout    Seconds a job may run before timing out (default: 60)
// --sleep      Seconds to wait before checking queue for jobs (default: 3)
// --tries      Number of times to attempt a job before logging it failed (default: 0)
php artisan queue:listen [--queue[="..."]] [--delay[="..."]] [--memory[="..."]] [--timeout[="..."]] [--sleep[="..."]] [--tries[="..."]] [connection]
// List all of the failed queue jobs
php artisan queue:failed
// Create a migration for the failed queue jobs database table
php artisan queue:failed-table
// Flush all of the failed queue jobs
php artisan queue:flush
// Delete a failed queue job
php artisan queue:forget
// Restart queue worker daemons after their current job
php artisan queue:restart
// Retry a failed queue job(id: The ID of the failed job)
php artisan queue:retry id
// Subscribe a URL to an Iron.io push queue
// queue: The name of Iron.io queue.
// url: The URL to be subscribed.
// --type       The push type for the queue.
php artisan queue:subscribe [--type[="..."]] queue url
// Process the next job on a queue
// --queue      The queue to listen on
// --daemon     Run the worker in daemon mode
// --delay      Amount of time to delay failed jobs (default: 0)
// --force      Force the worker to run even in maintenance mode
// --memory     The memory limit in megabytes (default: 128)
// --sleep      Number of seconds to sleep when no job is available (default: 3)
// --tries      Number of times to attempt a job before logging it failed (default: 0)
php artisan queue:work [--queue[="..."]] [--daemon] [--delay[="..."]] [--force] [--memory[="..."]] [--sleep[="..."]] [--tries[="..."]] [connection]

// Create a route cache file for faster route registration
php artisan route:cache
// Remove the route cache file
php artisan route:clear
// List all registered routes
php artisan route:list

// Run the scheduled commands
php artisan schedule:run

// Create a migration for the session database table
php artisan session:table

// Publish any publishable assets from vendor packages
// --force        Overwrite any existing files.
// --provider     The service provider that has assets you want to publish.
// --tag          The tag that has assets you want to publish.
php artisan vendor:publish [--force] [--provider[="..."]] [--tag[="..."]]
php artisan tail [--path[="..."]] [--lines[="..."]] [connection]
            

Composer

composer create-project laravel/laravel folder_name
composer install
composer update
composer dump-autoload [--optimize]
composer self-update
composer require [options] [--] [vendor/packages]...
            

Config

Config::get('app.timezone');
//get with Default value
Config::get('app.timezone', 'UTC');
//set Configuration
Config::set('database.default', 'sqlite');
            

Route

Route::get('foo', function(){});
Route::get('foo', 'ControllerName@function');
Route::controller('foo', 'FooController');
            
RESTful Controllers
Route::resource('posts','PostsController');
//Specify a subset of actions to handle on the route
Route::resource('photo', 'PhotoController',['only' => ['index', 'show']]);
Route::resource('photo', 'PhotoController',['except' => ['update', 'destroy']]);
            
Triggering Errors
App::abort(404);
$handler->missing(...) in ErrorServiceProvider::boot();
throw new NotFoundHttpException;
            
Route Parameters
Route::get('foo/{bar}', function($bar){});
Route::get('foo/{bar?}', function($bar = 'bar'){});
            
HTTP Verbs
Route::any('foo', function(){});
Route::post('foo', function(){});
Route::put('foo', function(){});
Route::patch('foo', function(){});
Route::delete('foo', function(){});
// RESTful actions
Route::resource('foo', 'FooController');
// Registering A Route For Multiple Verbs
Route::match(['get', 'post'], '/', function(){});
            
Secure Routes(TBD)
Route::get('foo', array('https', function(){}));
            
Route Constraints
Route::get('foo/{bar}', function($bar){})
->where('bar', '[0-9]+');
Route::get('foo/{bar}/{baz}', function($bar, $baz){})
->where(array('bar' => '[0-9]+', 'baz' => '[A-Za-z]'))
            
// Set a pattern to be used across routes
Route::pattern('bar', '[0-9]+')
            
HTTP Middleware
// Assigning Middleware To Routes
Route::get('admin/profile', ['middleware' => 'auth', function(){}]);
Route::get('admin/profile', function(){})->middleware('auth');
            
Named Routes
Route::currentRouteName();
Route::get('foo/bar', array('as' => 'foobar', function(){}));
Route::get('user/profile', [
'as' => 'profile', 'uses' => 'UserController@showProfile'
]);
Route::get('user/profile', 'UserController@showProfile')->name('profile');
$url = route('profile');
$redirect = redirect()->route('profile');
            
Route Prefixing
Route::group(['prefix' => 'admin'], function()
{
Route::get('users', function(){
    return 'Matches The "/admin/users" URL';
});
});
            
Route Namespacing
// This route group will carry the namespace 'Foo\Bar'
Route::group(array('namespace' => 'Foo\Bar'), function(){})
            
Sub-Domain Routing
// {sub} will be passed to the closure
Route::group(array('domain' => '{sub}.example.com'), function(){});
            

Environment

$environment = app()->environment();
$environment = App::environment();
$environment = $app->environment();
// The environment is local
if ($app->environment('local')){}
// The environment is either local OR staging...
if ($app->environment('local', 'staging')){}
            

Log

// The logger provides the seven logging levels defined in RFC 5424:
// debug, info, notice, warning, error, critical, and alert.
Log::info('info');
Log::info('info',array('context'=>'additional info'));
Log::error('error');
Log::warning('warning');
// get monolog instance
Log::getMonolog();
// add listener
Log::listen(function($level, $message, $context) {});
            
Query Logging
// enable the log
DB::connection()->enableQueryLog();
// get an array of the executed queries
DB::getQueryLog();
            

URL  

URL::full();
URL::current();
URL::previous();
URL::to('foo/bar', $parameters, $secure);
URL::action('NewsController@item', ['id'=>123]);
// need be in appropriate namespace
URL::action('Auth\AuthController@logout');
URL::action('FooController@method', $parameters, $absolute);
URL::route('foo', $parameters, $absolute);
URL::secure('foo/bar', $parameters);
URL::asset('css/foo.css', $secure);
URL::secureAsset('css/foo.css');
URL::isValidUrl('http://example.com');
URL::getRequest();
URL::setRequest($request);
            

Event

Event::fire('foo.bar', array($bar));
// Register an event listener with the dispatcher.
// void listen(string|array $events, mixed $listener, int $priority)
Event::listen('App\Events\UserSignup', function($bar){});
Event::listen('foo.*', function($bar){});
Event::listen('foo.bar', 'FooHandler', 10);
Event::listen('foo.bar', 'BarHandler', 5);
// Stopping The Propagation Of An Event
// You may do so by returning false from your handler.
Event::listen('foor.bar', function($event){ return false; });
Event::subscribe('UserEventHandler');
            

DB

Basic Database Usage
DB::connection('connection_name');
// Running A Select Query
$results = DB::select('select * from users where id = ?', [1]);
$results = DB::select('select * from users where id = :id', ['id' => 1]);
// Running A General Statement
DB::statement('drop table users');
// Listening For Query Events
DB::listen(function($sql, $bindings, $time){ code_here; });
// Database Transactions
DB::transaction(function()
{
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});
DB::beginTransaction();
DB::rollBack();
DB::commit();
            
Query Builder
// Retrieving All Rows From A Table
DB::table('name')->get();
// Chunking Results From A Table
DB::table('users')->chunk(100, function($users)
{
foreach ($users as $user)
{
    //
}
});
// Retrieving A Single Row From A Table
$user = DB::table('users')->where('name', 'John')->first();
DB::table('name')->first();
// Retrieving A Single Column From A Row
$name = DB::table('users')->where('name', 'John')->pluck('name');
DB::table('name')->pluck('column');
// Retrieving A List Of Column Values
$roles = DB::table('roles')->lists('title');
$roles = DB::table('roles')->lists('title', 'name');
// Specifying A Select Clause
$users = DB::table('users')->select('name', 'email')->get();
$users = DB::table('users')->distinct()->get();
$users = DB::table('users')->select('name as user_name')->get();
// Adding A Select Clause To An Existing Query
$query = DB::table('users')->select('name');
$users = $query->addSelect('age')->get();
// Using Where Operators
$users = DB::table('users')->where('votes', '>', 100)->get();
$users = DB::table('users')
            ->where('votes', '>', 100)
            ->orWhere('name', 'John')
            ->get();
$users = DB::table('users')
            ->whereBetween('votes', [1, 100])->get();
$users = DB::table('users')
            ->whereNotBetween('votes', [1, 100])->get();
$users = DB::table('users')
            ->whereIn('id', [1, 2, 3])->get();
$users = DB::table('users')
            ->whereNotIn('id', [1, 2, 3])->get();
$users = DB::table('users')
            ->whereNull('updated_at')->get();
DB::table('name')->whereNotNull('column')->get();
// Dynamic Where Clauses
$admin = DB::table('users')->whereId(1)->first();
$john = DB::table('users')
            ->whereIdAndEmail(2, 'john@doe.com')
            ->first();
$jane = DB::table('users')
            ->whereNameOrAge('Jane', 22)
            ->first();
// Order By, Group By, And Having
$users = DB::table('users')
            ->orderBy('name', 'desc')
            ->groupBy('count')
            ->having('count', '>', 100)
            ->get();
DB::table('name')->orderBy('column')->get();
DB::table('name')->orderBy('column','desc')->get();
DB::table('name')->having('count', '>', 100)->get();
// Offset & Limit
$users = DB::table('users')->skip(10)->take(5)->get();
        
Joins
// Basic Join Statement
DB::table('users')
        ->join('contacts', 'users.id', '=', 'contacts.user_id')
        ->join('orders', 'users.id', '=', 'orders.user_id')
        ->select('users.id', 'contacts.phone', 'orders.price')
        ->get();
// Left Join Statement
DB::table('users')
    ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
    ->get();
// select * from users where name = 'John' or (votes > 100 and title <> 'Admin')
DB::table('users')
        ->where('name', '=', 'John')
        ->orWhere(function($query)
        {
            $query->where('votes', '>', 100)
                    ->where('title', '<>', 'Admin');
        })
        ->get();
        
Aggregates
$users = DB::table('users')->count();
$price = DB::table('orders')->max('price');
$price = DB::table('orders')->min('price');
$price = DB::table('orders')->avg('price');
$total = DB::table('users')->sum('votes');
        
Raw Expressions
$users = DB::table('users')
                ->select(DB::raw('count(*) as user_count, status'))
                ->where('status', '<>', 1)
                ->groupBy('status')
                ->get();
// return rows
DB::select('select * from users where id = ?', array('value'));
// return nr affected rows
DB::insert('insert into foo set bar=2');
DB::update('update foo set bar=2');
DB::delete('delete from bar');
// returns void
DB::statement('update foo set bar=2');
// raw expression inside a statement
DB::table('name')->select(DB::raw('count(*) as count, column2'))->get();
        
Inserts / Updates / Deletes / Unions / Pessimistic Locking
// Inserts
DB::table('users')->insert(
['email' => 'john@example.com', 'votes' => 0]
);
$id = DB::table('users')->insertGetId(
['email' => 'john@example.com', 'votes' => 0]
);
DB::table('users')->insert([
['email' => 'taylor@example.com', 'votes' => 0],
['email' => 'dayle@example.com', 'votes' => 0]
]);
// Updates
DB::table('users')
        ->where('id', 1)
        ->update(['votes' => 1]);
DB::table('users')->increment('votes');
DB::table('users')->increment('votes', 5);
DB::table('users')->decrement('votes');
DB::table('users')->decrement('votes', 5);
DB::table('users')->increment('votes', 1, ['name' => 'John']);
// Deletes
DB::table('users')->where('votes', '<', 100)->delete();
DB::table('users')->delete();
DB::table('users')->truncate();
// Unions
// The unionAll() method is also available, and has the same method signature as union.
$first = DB::table('users')->whereNull('first_name');
$users = DB::table('users')->whereNull('last_name')->union($first)->get();
// Pessimistic Locking
DB::table('users')->where('votes', '>', 100)->sharedLock()->get();
DB::table('users')->where('votes', '>', 100)->lockForUpdate()->get();
            

Model

Basic Usage
// Defining An Eloquent Model
class User extends Model {}
// generate Eloquent models
php artisan make:model User
// specify a custom table name
class User extends Model {
protected $table = 'my_users';
}
        
More
Model::create(array('key' => 'value'));
// Find first matching record by attributes or create
Model::firstOrCreate(array('key' => 'value'));
// Find first record by attributes or instantiate
Model::firstOrNew(array('key' => 'value'));
// Create or update a record matching attibutes, and fill with values
Model::updateOrCreate(array('search_key' => 'search_value'), array('key' => 'value'));
// Fill a model with an array of attributes, beware of mass assignment!
Model::fill($attributes);
Model::destroy(1);
Model::all();
Model::find(1);
// Find using dual primary key
Model::find(array('first', 'last'));
// Throw an exception if the lookup fails
Model::findOrFail(1);
// Find using dual primary key and throw exception if the lookup fails
Model::findOrFail(array('first', 'last'));
Model::where('foo', '=', 'bar')->get();
Model::where('foo', '=', 'bar')->first();
Model::where('foo', '=', 'bar')->exists();
// dynamic
Model::whereFoo('bar')->first();
// Throw an exception if the lookup fails
Model::where('foo', '=', 'bar')->firstOrFail();
Model::where('foo', '=', 'bar')->count();
Model::where('foo', '=', 'bar')->delete();
//Output raw query
Model::where('foo', '=', 'bar')->toSql();
Model::whereRaw('foo = bar and cars = 2', array(20))->get();
Model::on('connection-name')->find(1);
Model::with('relation')->get();
Model::all()->take(10);
Model::all()->skip(10);
// Default Eloquent sort is ascendant
Model::all()->orderBy('column');
Model::all()->orderBy('column','desc');
            
Soft Delete
Model::withTrashed()->where('cars', 2)->get();
// Include the soft deleted models in the results
Model::withTrashed()->where('cars', 2)->restore();
Model::where('cars', 2)->forceDelete();
// Force the result set to only included soft deletes
Model::onlyTrashed()->where('cars', 2)->get();
            
Relationships
// One To One - User::phone()
return $this->hasOne('App\Phone', 'foreign_key', 'local_key');
// One To One - Phone::user(), The Inverse Of The Relation
return $this->belongsTo('App\User', 'foreign_key', 'other_key');

// One To Many - Post::comments()
return $this->hasMany('App\Comment', 'foreign_key', 'local_key');
//  One To Many - Comment::post()
return $this->belongsTo('App\Post', 'foreign_key', 'other_key');

// Many To Many - User::roles();
return $this->belongsToMany('App\Role', 'user_roles', 'user_id', 'role_id');
// Many To Many - Role::users();
return $this->belongsToMany('App\User');
// Many To Many - Retrieving Intermediate Table Columns
$role->pivot->created_at;
// Many To Many - Pivot table with extra attributes
return $this->belongsToMany('App\Role')->withPivot('column1', 'column2');
// Many To Many - Automatically maintained created_at and updated_at timestamps
return $this->belongsToMany('App\Role')->withTimestamps();

// Has Many Through - Country::posts(), A Country model have
// many Post models through an intermediate User model (User::country_id)
return $this->hasManyThrough('App\Post', 'App\User', 'country_id', 'user_id');

// Polymorphic Relations - Photo::imageable()
return $this->morphTo();
// Polymorphic Relations - Staff::photos()
return $this->morphMany('App\Photo', 'imageable');
// Polymorphic Relations - Product::photos()
return $this->morphMany('App\Photo', 'imageable');
// Polymorphic Relations - Register the morphMap in your AppServiceProvider
Relation::morphMap([
    'Post' => App\Post::class,
    'Comment' => App\Comment::class,
]);

// Many To Many Polymorphic Relations - Tables: posts,videos,tags,taggables
// Post::tags()
return $this->morphToMany('App\Tag', 'taggable');
// Video::tags()
return $this->morphToMany('App\Tag', 'taggable');
// Tag::posts()
return $this->morphedByMany('App\Post', 'taggable');
// Tag::videos()
return $this->morphedByMany('App\Video', 'taggable');

// Querying Relations
$user->posts()->where('active', 1)->get();
// Retrieve all posts that have at least one comment...
$posts = App\Post::has('comments')->get();
// Retrieve all posts that have three or more comments...
$posts = Post::has('comments', '>=', 3)->get();
// Retrieve all posts that have at least one comment with votes...
$posts = Post::has('comments.votes')->get();
// Retrieve all posts with at least one comment containing words like foo%
$posts = Post::whereHas('comments', function ($query) {
    $query->where('content', 'like', 'foo%');
})->get();

// Eager Loading
$books = App\Book::with('author')->get();
$books = App\Book::with('author', 'publisher')->get();
$books = App\Book::with('author.contacts')->get();

// Lazy Eager Loading
$books->load('author', 'publisher');

// Inserting Related Models
$comment = new App\Comment(['message' => 'A new comment.']);
$post->comments()->save($comment);
// save multiple related models
$post->comments()->saveMany([
    new App\Comment(['message' => 'A new comment.']),
    new App\Comment(['message' => 'Another comment.']),
]);
$post->comments()->create(['message' => 'A new comment.']);

// Updating a belongsTo relationship
$user->account()->associate($account);
$user->save();
$user->account()->dissociate();
$user->save();

// Inserting Related Models - Many To Many Relationships
$user->roles()->attach($roleId);
$user->roles()->attach($roleId, ['expires' => $expires]);
// Detach a single role from the user...
$user->roles()->detach($roleId);
// Detach all roles from the user...
$user->roles()->detach();
$user->roles()->detach([1, 2, 3]);
$user->roles()->attach([1 => ['expires' => $expires], 2, 3]);

// Any IDs that are not in the given array will be removed from the intermediate table.
$user->roles()->sync([1, 2, 3]);
// You may also pass additional intermediate table values with the IDs:
$user->roles()->sync([1 => ['expires' => true], 2, 3]);

            
Events
Model::creating(function($model){});
Model::created(function($model){});
Model::updating(function($model){});
Model::updated(function($model){});
Model::saving(function($model){});
Model::saved(function($model){});
Model::deleting(function($model){});
Model::deleted(function($model){});
Model::observe(new FooObserver);
            
Eloquent Configuration
// Disables mass assignment exceptions from being thrown from model inserts and updates
Eloquent::unguard();
// Renables any ability to throw mass assignment exceptions
Eloquent::reguard();
            

Pagination

// Auto-Magic Pagination
Model::paginate(15);
Model::where('cars', 2)->paginate(15);
// "Next" and "Previous" only
Model::where('cars', 2)->simplePaginate(15);
// Manual Paginator
Paginator::make($items, $totalItems, $perPage);
// Print page navigators in view
$variable->links();
            

Lang

App::setLocale('en');
Lang::get('messages.welcome');
Lang::get('messages.welcome', array('foo' => 'Bar'));
Lang::has('messages.welcome');
Lang::choice('messages.apples', 10);
// Lang::get alias
trans('messages.welcome');
            

File

File::exists('path');
File::get('path');
File::getRemote('path');
// Get a file's contents by requiring it
File::getRequire('path');
// Require the given file once
File::requireOnce('path');
// Write the contents of a file
File::put('path', 'contents');
// Append to a file
File::append('path', 'data');
// Delete the file at a given path
File::delete('path');
// Move a file to a new location
File::move('path', 'target');
// Copy a file to a new location
File::copy('path', 'target');
// Extract the file extension from a file path
File::extension('path');
// Get the file type of a given file
File::type('path');
// Get the file size of a given file
File::size('path');
// Get the file's last modification time
File::lastModified('path');
// Determine if the given path is a directory
File::isDirectory('directory');
// Determine if the given path is writable
File::isWritable('path');
// Determine if the given path is a file
File::isFile('file');
// Find path names matching a given pattern.
File::glob($patterns, $flag);
// Get an array of all files in a directory.
File::files('directory');
// Get all of the files from the given directory (recursive).
File::allFiles('directory');
// Get all of the directories within a given directory.
File::directories('directory');
// Create a directory
File::makeDirectory('path',  $mode = 0777, $recursive = false);
// Copy a directory from one location to another
File::copyDirectory('directory', 'destination', $options = null);
// Recursively delete a directory
File::deleteDirectory('directory', $preserve = false);
// Empty the specified directory of all files and folders
File::cleanDirectory('directory');
            

UnitTest

Install and run
// add to composer and update:
"phpunit/phpunit": "4.0.*"
// run tests (from project root)
./vendor/bin/phpunit
            
Asserts
$this->assertTrue(true);
$this->assertEquals('foo', $bar);
$this->assertCount(1,$times);
$this->assertResponseOk();
$this->assertResponseStatus(403);
$this->assertRedirectedTo('foo');
$this->assertRedirectedToRoute('route.name');
$this->assertRedirectedToAction('Controller@method');
$this->assertViewHas('name');
$this->assertViewHas('age', $value);
$this->assertSessionHasErrors();
// Asserting the session has errors for a given key...
$this->assertSessionHasErrors('name');
// Asserting the session has errors for several keys...
$this->assertSessionHasErrors(array('name', 'age'));
$this->assertHasOldInput();
            
Calling routes
$response = $this->call($method, $uri, $parameters, $files, $server, $content);
$response = $this->callSecure('GET', 'foo/bar');
$this->session(['foo' => 'bar']);
$this->flushSession();
$this->seed();
$this->seed($connection);
            

SSH

Executing Commands
SSH::run(array $commands);
SSH::into($remote)->run(array $commands); // specify remote, otherwise assumes default
SSH::run(array $commands, function($line)
{
echo $line.PHP_EOL;
});
            
Tasks
// define
SSH::define($taskName, array $commands);
// execute
SSH::task($taskName, function($line)
{
echo $line.PHP_EOL;
});
            
SFTP Uploads
SSH::put($localFile, $remotePath);
SSH::putString($string, $remotePath);
            

Schema

// Indicate that the table needs to be created
Schema::create('table', function($table)
{
$table->increments('id');
});
// Specify a Connection
Schema::connection('foo')->create('table', function($table){});
// Rename the table to a given name
Schema::rename($from, $to);
// Indicate that the table should be dropped
Schema::drop('table');
// Indicate that the table should be dropped if it exists
Schema::dropIfExists('table');
// Determine if the given table exists
Schema::hasTable('table');
// Determine if the given table has a given column
Schema::hasColumn('table', 'column');
// Update an existing table
Schema::table('table', function($table){});
// Indicate that the given columns should be renamed
$table->renameColumn('from', 'to');
// Indicate that the given columns should be dropped
$table->dropColumn(string|array);
// The storage engine that should be used for the table
$table->engine = 'InnoDB';
// Only work on MySQL
$table->string('name')->after('email');
            
Indexes
$table->string('column')->unique();
$table->primary('column');
// Creates a dual primary key
$table->primary(array('first', 'last'));
$table->unique('column');
$table->unique('column', 'key_name');
// Creates a dual unique index
$table->unique(array('first', 'last'));
$table->unique(array('first', 'last'), 'key_name');
$table->index('column');
$table->index('column', 'key_name');
// Creates a dual index
$table->index(array('first', 'last'));
$table->index(array('first', 'last'), 'key_name');
$table->dropPrimary(array('column'));
$table->dropPrimary('table_column_primary');
$table->dropUnique(array('column'));
$table->dropUnique('table_column_unique');
$table->dropIndex(array('column'));
$table->dropIndex('table_column_index');
            
Foreign Keys
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'|'restrict'|'set null'|'no action');
$table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade'|'restrict'|'set null'|'no action');
$table->dropForeign(array('user_id'));
$table->dropForeign('posts_user_id_foreign');
            
Column Types
// Increments
$table->increments('id');
$table->bigIncrements('id');

// Numbers
$table->integer('votes');
$table->tinyInteger('votes');
$table->smallInteger('votes');
$table->mediumInteger('votes');
$table->bigInteger('votes');
$table->float('amount');
$table->double('column', 15, 8);
$table->decimal('amount', 5, 2);

//String and Text
$table->char('name', 4);
$table->string('email');
$table->string('name', 100);
$table->text('description');
$table->mediumText('description');
$table->longText('description');

//Date and Time
$table->date('created_at');
$table->dateTime('created_at');
$table->time('sunrise');
$table->timestamp('added_on');
// Adds created_at and updated_at columns
$table->timestamps();
$table->nullableTimestamps();

// Others
$table->binary('data');
$table->boolean('confirmed');
// Adds deleted_at column for soft deletes
$table->softDeletes();
$table->enum('choices', array('foo', 'bar'));
// Adds remember_token as VARCHAR(100) NULL
$table->rememberToken();
// Adds INTEGER parent_id and STRING parent_type
$table->morphs('parent');
->nullable()
->default($value)
->unsigned()
            

Input

Input::get('key');
// Default if the key is missing
Input::get('key', 'default');
Input::has('key');
Input::all();
// Only retrieve 'foo' and 'bar' when getting input
Input::only('foo', 'bar');
// Disregard 'foo' when getting input
Input::except('foo');
Input::flush();
            
Session Input (flash)
// Flash input to the session
Input::flash();
// Flash only some of the input to the session
Input::flashOnly('foo', 'bar');
// Flash only some of the input to the session
Input::flashExcept('foo', 'baz');
// Retrieve an old input item
Input::old('key','default_value');
            
Files
// Use a file that's been uploaded
Input::file('filename');
// Determine if a file was uploaded
Input::hasFile('filename');
// Access file properties
Input::file('name')->getRealPath();
Input::file('name')->getClientOriginalName();
Input::file('name')->getClientOriginalExtension();
Input::file('name')->getSize();
Input::file('name')->getMimeType();
// Move an uploaded file
Input::file('name')->move($destinationPath);
// Move an uploaded file
Input::file('name')->move($destinationPath, $fileName);
            

Cache

Cache::put('key', 'value', $minutes);
Cache::add('key', 'value', $minutes);
Cache::forever('key', 'value');
Cache::remember('key', $minutes, function(){ return 'value' });
Cache::rememberForever('key', function(){ return 'value' });
Cache::forget('key');
Cache::has('key');
Cache::get('key');
Cache::get('key', 'default');
Cache::get('key', function(){ return 'default'; });
Cache::tags('my-tag')->put('key','value', $minutes);
Cache::tags('my-tag')->has('key');
Cache::tags('my-tag')->get('key');
Cache::tags('my-tag')->forget('key');
Cache::tags('my-tag')->flush();
Cache::increment('key');
Cache::increment('key', $amount);
Cache::decrement('key');
Cache::decrement('key', $amount);
Cache::section('group')->put('key', $value);
Cache::section('group')->get('key');
Cache::section('group')->flush();
            

Cookie

Cookie::get('key');
Cookie::get('key', 'default');
// Create a cookie that lasts for ever
Cookie::forever('key', 'value');
// Create a cookie that lasts N minutes
Cookie::make('key', 'value', 'minutes');
// Set a cookie before a response has been created
Cookie::queue('key', 'value', 'minutes');
// Forget cookie
Cookie::forget('key');
// Send a cookie with a response
$response = Response::make('Hello World');
// Add a cookie to the response
$response->withCookie(Cookie::make('name', 'value', $minutes));
            

Session

Session::get('key');
// Returns an item from the session
Session::get('key', 'default');
Session::get('key', function(){ return 'default'; });
// Get the session ID
Session::getId();
// Put a key / value pair in the session
Session::put('key', 'value');
// Push a value into an array in the session
Session::push('foo.bar','value');
// Returns all items from the session
Session::all();
// Checks if an item is defined
Session::has('key');
// Remove an item from the session
Session::forget('key');
// Remove all of the items from the session
Session::flush();
// Generate a new session identifier
Session::regenerate();
// Flash a key / value pair to the session
Session::flash('key', 'value');
// Reflash all of the session flash data
Session::reflash();
// Reflash a subset of the current flash data
Session::keep(array('key1', 'key2'));
            

Request

// url: http://xx.com/aa/bb
Request::url();
// path: /aa/bb
Request::path();
// getRequestUri: /aa/bb/?c=d
Request::getRequestUri();
// Returns user's IP
Request::ip();
// getUri: http://xx.com/aa/bb/?c=d
Request::getUri();
// getQueryString: c=d
Request::getQueryString();
// Get the port scheme of the request (e.g., 80, 443, etc.)
Request::getPort();
// Determine if the current request URI matches a pattern
Request::is('foo/*');
// Get a segment from the URI (1 based index)
Request::segment(1);
// Retrieve a header from the request
Request::header('Content-Type');
// Retrieve a server variable from the request
Request::server('PATH_INFO');
// Determine if the request is the result of an AJAX call
Request::ajax();
// Determine if the request is over HTTPS
Request::secure();
// Get the request method
Request::method();
// Checks if the request method is of specified type
Request::isMethod('post');
// Get raw POST data
Request::instance()->getContent();
// Get requested response format
Request::format();
// true if HTTP Content-Type header contains */json
Request::isJson();
// true if HTTP Accept header is application/json
Request::wantsJson();

            

Response

return Response::make($contents);
return Response::make($contents, 200);
return Response::json(array('key' => 'value'));
return Response::json(array('key' => 'value'))
->setCallback(Input::get('callback'));
return Response::download($filepath);
return Response::download($filepath, $filename, $headers);
// Create a response and modify a header value
$response = Response::make($contents, 200);
$response->header('Content-Type', 'application/json');
return $response;
// Attach a cookie to a response
return Response::make($content)
->withCookie(Cookie::make('key', 'value'));
            

Redirect

return Redirect::to('foo/bar');
return Redirect::to('foo/bar')->with('key', 'value');
return Redirect::to('foo/bar')->withInput(Input::get());
return Redirect::to('foo/bar')->withInput(Input::except('password'));
return Redirect::to('foo/bar')->withErrors($validator);
// Create a new redirect response to the previous location
return Redirect::back();
// Create a new redirect response to a named route
return Redirect::route('foobar');
return Redirect::route('foobar', array('value'));
return Redirect::route('foobar', array('key' => 'value'));
// Create a new redirect response to a controller action
return Redirect::action('FooController@index');
return Redirect::action('FooController@baz', array('value'));
return Redirect::action('FooController@baz', array('key' => 'value'));
// If intended redirect is not defined, defaults to foo/bar.
return Redirect::intended('foo/bar');
            

Container

App::bind('foo', function($app){ return new Foo; });
App::make('foo');
// If this class exists, it's returned
App::make('FooBar');
// Register a shared binding in the container
App::singleton('foo', function(){ return new Foo; });
// Register an existing instance as shared in the container
App::instance('foo', new Foo);
// Register a binding with the container
App::bind('FooRepositoryInterface', 'BarRepository');
// Register a service provider with the application
App::register('FooServiceProvider');
// Listen for object resolution
App::resolving(function($object){});
            

Security

Hashing
Hash::make('secretpassword');
Hash::check('secretpassword', $hashedPassword);
Hash::needsRehash($hashedPassword);
            
Encryption
Crypt::encrypt('secretstring');
Crypt::decrypt($encryptedString);
Crypt::setMode('ctr');
Crypt::setCipher($cipher);
            

Auth

Authentication
// Determine if the current user is authenticated
Auth::check();
// Get the currently authenticated user
Auth::user();
// Get the ID of the currently authenticated user
Auth::id();
// Attempt to authenticate a user using the given credentials
Auth::attempt(array('email' => $email, 'password' => $password));
// 'Remember me' by passing true to Auth::attempt()
Auth::attempt($credentials, true);
// Log in for a single request
Auth::once($credentials);
// Log a user into the application
Auth::login(User::find(1));
// Log the given user ID into the application
Auth::loginUsingId(1);
// Log the user out of the application
Auth::logout();
// Validate a user's credentials
Auth::validate($credentials);
// Attempt to authenticate using HTTP Basic Auth
Auth::basic('username');
// Perform a stateless HTTP Basic login attempt
Auth::onceBasic();
// Send a password reminder to a user
Password::remind($credentials, function($message, $user){});
            
Authorization
// Define abilities
Gate::define('update-post', 'Class@method');
Gate::define('update-post', function ($user, $post) {...});
// Passing multiple argument
Gate::define('delete-comment', function ($user, $post, $comment) {});

// Check abilities
Gate::denies('update-post', $post);
Gate::allows('update-post', $post);
Gate::check('update-post', $post);
// Specified a user for checking
Gate::forUser($user)->allows('update-post', $post);
// Through User model, using Authorizable trait
User::find(1)->can('update-post', $post);
User::find(1)->cannot('update-post', $post);

// Intercepting Authorization Checks
Gate::before(function ($user, $ability) {});
Gate::after(function ($user, $ability) {});

// Chekcing in Blade template
@can('update-post', $post)
@endcan
// with else
@can('update-post', $post)
@else
@endcan

// Generate a Policy
php artisan make:policy PostPolicy
// `policy` helper function
policy($post)->update($user, $post)

// Controller Authorization
$this->authorize('update', $post);
// for $user
$this->authorizeForUser($user, 'update', $post);

                    

Mail

Mail::send('email.view', $data, function($message){});
Mail::send(array('html.view', 'text.view'), $data, $callback);
Mail::queue('email.view', $data, function($message){});
Mail::queueOn('queue-name', 'email.view', $data, $callback);
Mail::later(5, 'email.view', $data, function($message){});
// Write all email to logs instead of sending
Mail::pretend();
            
Messages
// These can be used on the $message instance passed into Mail::send() or Mail::queue()
$message->from('email@example.com', 'Mr. Example');
$message->sender('email@example.com', 'Mr. Example');
$message->returnPath('email@example.com');
$message->to('email@example.com', 'Mr. Example');
$message->cc('email@example.com', 'Mr. Example');
$message->bcc('email@example.com', 'Mr. Example');
$message->replyTo('email@example.com', 'Mr. Example');
$message->subject('Welcome to the Jungle');
$message->priority(2);
$message->attach('foo\bar.txt', $options);
// This uses in-memory data as attachments
$message->attachData('bar', 'Data Name', $options);
// Embed a file in the message and get the CID
$message->embed('foo\bar.txt');
$message->embedData('foo', 'Data Name', $options);
// Get the underlying Swift Message instance
$message->getSwiftMessage();
            

Queue

Queue::push('SendMail', array('message' => $message));
Queue::push('SendEmail@send', array('message' => $message));
Queue::push(function($job) use $id {});
// Same payload to multiple workers
Queue::bulk(array('SendEmail', 'NotifyUser'), $payload);
// Starting the queue listener
php artisan queue:listen
php artisan queue:listen connection
php artisan queue:listen --timeout=60
// Process only the first job on the queue
php artisan queue:work
// Start a queue worker in daemon mode
php artisan queue:work --daemon
// Create migration file for failed jobs
php artisan queue:failed-table
// Listing failed jobs
php artisan queue:failed
// Delete failed job by id
php artisan queue:forget 5
// Delete all failed jobs
php artisan queue:flush
            

Validation

Validator::make(
array('key' => 'Foo'),
array('key' => 'required|in:Foo')
);
Validator::extend('foo', function($attribute, $value, $params){});
Validator::extend('foo', 'FooValidator@validate');
Validator::resolver(function($translator, $data, $rules, $msgs)
{
return new FooValidator($translator, $data, $rules, $msgs);
});
            
Rules
accepted
active_url
after:YYYY-MM-DD
before:YYYY-MM-DD
alpha
alpha_dash
alpha_num
array
between:1,10
confirmed
date
date_format:YYYY-MM-DD
different:fieldname
digits:value
digits_between:min,max
boolean
email
exists:table,column
image
in:foo,bar,...
not_in:foo,bar,...
integer
numeric
ip
max:value
min:value
mimes:jpeg,png
regex:[0-9]
required
required_if:field,value
required_with:foo,bar,...
required_with_all:foo,bar,...
required_without:foo,bar,...
required_without_all:foo,bar,...
same:field
size:value
timezone
unique:table,column,except,idColumn
url

            

View

View::make('path/to/view');
View::make('foo/bar')->with('key', 'value');
View::make('foo/bar')->withKey('value');
View::make('foo/bar', array('key' => 'value'));
View::exists('foo/bar');
// Share a value across all views
View::share('key', 'value');
// Nesting views
View::make('foo/bar')->nest('name', 'foo/baz', $data);
// Register a view composer
View::composer('viewname', function($view){});
//Register multiple views to a composer
View::composer(array('view1', 'view2'), function($view){});
// Register a composer class
View::composer('viewname', 'FooComposer');
View::creator('viewname', function($view){});
            

Blade

// Show a section in a template
@yield('name')
@extends('layout.name')
// Begin a section
@section('name')
// End a section
@stop
// End a section and yield
@section('sidebar')
@show
@parent

@include('view.name')
@include('view.name', array('key' => 'value'));
@lang('messages.name')
@choice('messages.name', 1);

@if
@else
@elseif
@endif

@unless
@endunless

@for
@endfor

@foreach
@endforeach

@while
@endwhile

//forelse 4.2 feature
@forelse($users as $user)
@empty
@endforelse

// Echo content
{{ $var }}
// Echo escaped content
{{{ $var }}}
// Echo unescaped content; 5.0 feature
{!! $var !!}
{{-- Blade Comment --}}
// Echoing Data After Checking For Existence
{{{ $name or 'Default' }}}
// Displaying Raw Text With Curly Braces
@{{ This will not be processed by Blade }}
            

Form

Form::open(array('url' => 'foo/bar', 'method' => 'PUT'));
Form::open(array('route' => 'foo.bar'));
Form::open(array('route' => array('foo.bar', $parameter)));
Form::open(array('action' => 'FooController@method'));
Form::open(array('action' => array('FooController@method', $parameter)));
Form::open(array('url' => 'foo/bar', 'files' => true));
Form::close();
Form::token();
Form::model($foo, array('route' => array('foo.bar', $foo->bar)));

            
Form Elements
Form::label('id', 'Description');
Form::label('id', 'Description', array('class' => 'foo'));
Form::text('name');
Form::text('name', $value);
Form::text('name', $value, array('class' => 'name'));
Form::textarea('name');
Form::textarea('name', $value);
Form::textarea('name', $value, array('class' => 'name'));
Form::hidden('foo', $value);
Form::password('password');
Form::password('password', array('placeholder' => 'Password'));
Form::email('name', $value, array());
Form::file('name', array('class' => 'name'));
Form::checkbox('name', 'value');
// Generating a checkbox that is checked
Form::checkbox('name', 'value', true, array('class' => 'name'));
Form::radio('name', 'value');
// Generating a radio input that is selected
Form::radio('name', 'value', true, array('class' => 'name'));
Form::select('name', array('key' => 'value'));
Form::select('name', array('key' => 'value'), 'key', array('class' => 'name'));
Form::selectRange('range', 1, 10);
Form::selectYear('year', 2011, 2015);
Form::selectMonth('month');
Form::submit('Submit!', array('class' => 'name'));
Form::button('name', array('class' => 'name'));
Form::macro('fooField', function()
{
return '<input type="custom"/>';
});
Form::fooField();
            

HTML

HTML::macro('name', function(){});
// Convert an HTML string to entities
HTML::entities($value);
// Convert entities to HTML characters
HTML::decode($value);
// Generate a link to a JavaScript file
HTML::script($url, $attributes);
// Generate a link to a CSS file
HTML::style($url, $attributes);
// Generate an HTML image element
HTML::image($url, $alt, $attributes);
// Generate a HTML link
HTML::link($url, 'title', $attributes, $secure);
// Generate a HTTPS HTML link
HTML::secureLink($url, 'title', $attributes);
// Generate a HTML link to an asset
HTML::linkAsset($url, 'title', $attributes, $secure);
// Generate a HTTPS HTML link to an asset
HTML::linkSecureAsset($url, 'title', $attributes);
// Generate a HTML link to a named route
HTML::linkRoute($name, 'title', $parameters, $attributes);
// Generate a HTML link to a controller action
HTML::linkAction($action, 'title', $parameters, $attributes);
// Generate a HTML link to an email address
HTML::mailto($email, 'title', $attributes);
// Obfuscate an e-mail address to prevent spam-bots from sniffing it
HTML::email($email);
// Generate an ordered list of items
HTML::ol($list, $attributes);
// Generate an un-ordered list of items
HTML::ul($list, $attributes);
// Create a listing HTML element
HTML::listing($type, $list, $attributes);
// Create the HTML for a listing element
HTML::listingElement($key, $type, $value);
// Create the HTML for a nested listing attribute
HTML::nestedListing($key, $type, $value);
// Build an HTML attribute string from an array
HTML::attributes($attributes);
// Build a single attribute element
HTML::attributeElement($key, $value);
// Obfuscate a string to prevent spam-bots from sniffing it
HTML::obfuscate($value);
            

String

// Transliterate a UTF-8 value to ASCII
Str::ascii($value)
Str::camel($value)
Str::contains($haystack, $needle)
Str::endsWith($haystack, $needles)
// Cap a string with a single instance of a given value.
Str::finish($value, $cap)
Str::is($pattern, $value)
Str::length($value)
Str::limit($value, $limit = 100, $end = '...')
Str::lower($value)
Str::words($value, $words = 100, $end = '...')
Str::plural($value, $count = 2)
// Generate a more truly "random" alpha-numeric string.
Str::random($length = 16)
// Generate a "random" alpha-numeric string.
Str::quickRandom($length = 16)
Str::upper($value)
Str::title($value)
Str::singular($value)
Str::slug($title, $separator = '-')
Str::snake($value, $delimiter = '_')
Str::startsWith($haystack, $needles)
// Convert a value to studly caps case.
Str::studly($value)
Str::macro($name, $macro)
            

Helper

Arrays
// adds a given key / value pair to the array if the
// given key doesn't already exist in the array
array_add($array, 'key', 'value');
// collapse an array of arrays into a single array
array_collapse($array);
// Divide an array into two arrays. One with keys and the other with values
array_divide($array);
// Flatten a multi-dimensional associative array with dots
array_dot($array);
// Get all of the given array except for a specified array of items
array_except($array, array('key'));
// Return the first element in an array passing a given truth test
array_first($array, function($key, $value){}, $default);
// Strips keys from the array
array_flatten($array);
// Remove one or many array items from a given array using "dot" notation
array_forget($array, 'foo');
// Dot notation
array_forget($array, 'foo.bar');
// Get an item from an array using "dot" notation
array_get($array, 'foo', 'default');
array_get($array, 'foo.bar', 'default');
// Checks that a given item exists in an array using "dot" notation
array_has($array, 'products.desk');
// Get a subset of the items from the given array
array_only($array, array('key'));
// Return array of key => values
array_pluck($array, 'key');
// Return and remove 'key' from array
array_pull($array, 'key');
// Set an array item to a given value using "dot" notation
array_set($array, 'key', 'value');
// Dot notation
array_set($array, 'key.subkey', 'value');
// Sorts the array by the results of the given Closure
array_sort($array, function(){});
// Recursively sorts the array using the sort function
array_sort_recursive();
// Filters the array using the given Closure
array_where();
// First element of an array
head($array);
// Last element of an array
last($array);
            
Paths
// Fully qualified path to the app directory
app_path();
// Get the path to the public folder
base_path();
// Fully qualified path to the application configuration directory
config_path();
// Fully qualified path to the application's database directory
database_path();
// Gets the path to the versioned Elixir file:
elixir();
// Fully qualified path to the public directory
public_path();
// Get the path to the storage folder
storage_path();
            
Strings
// Convert a value to camel case
camel_case($value);
// Get the class "basename" of the given object / class
class_basename($class);
// Escape a string
e('<html>');
// Determine if a given string starts with a given substring
starts_with('Foo bar.', 'Foo');
// Determine if a given string ends with a given substring
ends_with('Foo bar.', 'bar.');
// Convert a string to snake case
snake_case('fooBar');
// Limits the number of characters in a string
str_limit();
// Determine if a given string contains a given substring
str_contains('Hello foo bar.', 'foo');
// Result: foo/bar/
str_finish('foo/bar', '/');
str_is('foo*', 'foobar');
str_plural('car');
str_random(25);
str_singular('cars');
str_slug("Laravel 5 Framework", "-");
// Result: FooBar
studly_case('foo_bar');
trans('foo.bar');
trans_choice('foo.bar', $count);
            
URLs and Links
action('FooController@method', $parameters);
// HTML Link
asset('img/photo.jpg', $title, $attributes);
// HTTPS link
secure_asset('img/photo.jpg', $title, $attributes);
route($route, $parameters, $absolute = true);
url('path', $parameters = array(), $secure = null);
            
Miscellaneous
// Authenticator instance (Auth)
auth()->user();
// Generates a redirect response to the user's previous location
back();
// Hashes the given value using Bcrypt (Hash)
bcrypt('my-secret-password');
// Creates a collection instance from the supplied items
collect(['taylor', 'abigail']);
// Gets the value of a configuration variable
config('app.timezone', $default);
// Generates an HTML hidden input field containing the value of the CSRF token
{!! csrf_field() !!}
// Retrieves the value of the current CSRF token
$token = csrf_token();
// Dumps the given variable and ends execution of the script
dd($value);
// Gets the value of an environment variable or returns a default value
$env = env('APP_ENV');
$env = env('APP_ENV', 'production');
// Dispatches the given event to its listeners:
event(new UserRegistered($user));
// Creates a model factory builder for a given class
$user = factory(App\User::class)->make();
// Generates an HTML hidden input field containing the spoofed value of the form's HTTP verb
{!! method_field('delete') !!}
// Retrieves an old input value flashed into the session
$value = old('value');
$value = old('value', 'default');
// Returns an instance of the redirector to do redirects:
return redirect('/home');
// Returns the current request instance or obtains an input item
$value = request('key', $default = null)
// Creates a response instance or obtains an instance of the response factory
return response('Hello World', 200, $headers);
// Used to get / set a session value
$value = session('key');
$value = session()->get('key');
session()->put('key', $value);
// Will simply return the value it is given.
value(function(){ return 'bar'; });
// Retrieves a view instance
return view('auth.login');
// Returns the value it is given
$value = with(new Foo)->work();
            

Collection

// Creating Collections
collect([1, 2, 3]);
// Simply returns the underlying array represented by the collection:
$collection->all();
// Returns the average of all items in the collection:
$collection->avg();
// Breaks the collection into multiple, smaller collections of a given size:
$collection->chunk(4);
// Collapses a collection of arrays into a flat collection:
$collection->collapse();
// Determines whether the collection contains a given item:
$collection->contains('New York');
// Returns the total number of items in the collection:
$collection->count();
// Iterates over the items in the collection and passes each item to a given callback:
$collection = $collection->each(function ($item, $key) {
});
// Creates a new collection consisting of every n-th element:
$collection->every(4);
// Pass offset as the second argument:
$collection->every(4, 1);
// Returns all items in the collection except for those with the specified keys:
$collection->except(['price', 'discount']);
// Filters the collection by a given callback:
$filtered = $collection->filter(function ($item) {
    return $item > 2;
});
// Returns the first element in the collection that passes a given truth test:
collect([1, 2, 3, 4])->first(function ($key, $value) {
    return $value > 2;
});
// Flattens a multi-dimensional collection into a single dimension:
$flattened = $collection->flatten();
// Swaps the collection's keys with their corresponding values:
$flipped = $collection->flip();
// Removes an item from the collection by its key:
$collection->forget('name');
// Returns a new collection containing the items:
$chunk = $collection->forPage(2, 3);
// Returns the item at a given key. If the key does not exist, null is returned:
$value = $collection->get('name');
// Groups the collection's items by a given key:
$grouped = $collection->groupBy('account_id');
// Determines if a given key exists in the collection:
$collection->has('email');
// Joins the items in a collection:
$collection->implode('product', ', ');
// Removes any values that are not present in the given array or collection:
$intersect = $collection->intersect(['Desk', 'Chair', 'Bookcase']);
// Returns true if the collection is empty:
collect([])->isEmpty();
// Keys the collection by the given key:
$keyed = $collection->keyBy('product_id');
// Pass a callback, which should return the value to key the collection by:
$keyed = $collection->keyBy(function ($item) {
    return strtoupper($item['product_id']);
});
// Returns all of the collection's keys:
$keys = $collection->keys();
// Returns the last element in the collection:
$collection->last();
// Iterates through the collection and passes each value to the given callback:
$multiplied = $collection->map(function ($item, $key) {
    return $item * 2;
});
// Return the maximum value of a given key:
$max = collect([['foo' => 10], ['foo' => 20]])->max('foo');
$max = collect([1, 2, 3, 4, 5])->max();
// Merges the given array into the collection:
$merged = $collection->merge(['price' => 100, 'discount' => false]);
// Return the minimum value of a given key:
$min = collect([['foo' => 10], ['foo' => 20]])->min('foo');
$min = collect([1, 2, 3, 4, 5])->min();
// Returns the items in the collection with the specified keys:
$filtered = $collection->only(['product_id', 'name']);
// Retrieves all of the collection values for a given key:
$plucked = $collection->pluck('name');
// Removes and returns the last item from the collection:
$collection->pop();
// Adds an item to the beginning of the collection:
$collection->prepend(0);
// Pass a second argument to set the key of the prepended item:
$collection->prepend(0, 'zero');
// Removes and returns an item from the collection by its key:
$collection->pull('name');
// Appends an item to the end of the collection:
$collection->push(5);
// Sets the given key and value in the collection:
$collection->put('price', 100);
// Returns a random item from the collection:
$collection->random();
// Pass an integer to random. If that integer is more than 1, a collection of items is returned:
$random = $collection->random(3);
// Reduces the collection to a single value:
$total = $collection->reduce(function ($carry, $item) {
    return $carry + $item;
});
// Filters the collection using the given callback:
$filtered = $collection->reject(function ($item) {
    return $item > 2;
});
// Reverses the order of the collection's items:
$reversed = $collection->reverse();
// Searches the collection for the given value and returns its key if found:
$collection->search(4);
// Removes and returns the first item from the collection:
$collection->shift();
// Randomly shuffles the items in the collection:
$shuffled = $collection->shuffle();
// Returns a slice of the collection starting at the given index:
$slice = $collection->slice(4);
// Sorts the collection:
$sorted = $collection->sort();
// Sorts the collection by the given key:
$sorted = $collection->sortBy('price');
// Removes and returns a slice of items starting at the specified index:
$chunk = $collection->splice(2);
// Returns the sum of all items in the collection:
collect([1, 2, 3, 4, 5])->sum();
// Returns a new collection with the specified number of items:
$chunk = $collection->take(3);
// Converts the collection into a plain PHP array:
$collection->toArray();
// Converts the collection into JSON:
$collection->toJson();
// Iterates over the collection:
$collection->transform(function ($item, $key) {
    return $item * 2;
});
// Returns all of the unique items in the collection:
$unique = $collection->unique();
// Returns a new collection with the keys reset to consecutive integers:
$values = $collection->values();
// Filters the collection by a given key / value pair:
$filtered = $collection->where('price', 100);
// Merges together the values of the given array with the values of the collection:
$zipped = $collection->zip([100, 200]);
                

referensi : https://summerblue.github.io