16
Jan
2018

Carbon & Moment.js

16 Jan 2018
    //  check if expired
    Carbon::parse($createdAt)->addSeconds($this->expires)->isPast();


    // diff in seconds
    $then = Carbon::now()->addMinute();
    $now = Carbon::now();
    
    $then->diffInSeconds($now, false) // -60
    $now->diffInSeconds($then, false) // 60
12
Jan
2018

xdebug

12 Jan 2018

sudo subl /etc/php/7.1/cli/php.ini sudo subl /etc/php/7.1/fpm/php.ini

[Xdebug]
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler="dbgp"
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.idekey="PHPSTORM"
8
Sep
2017

PhpStorm

08 Sep 2017

Hotkeys

Ctrl + ]           goto next bracket
Ctrl + Shift + ]   select all for next bracket
Ctrl + Shift + M   jump before or after closest bracket
ALT + Up | Down    next function
ALT + Home         breadcrumbs

Live templates

7
Sep
2017

Nginx Application Server

07 Sep 2017

Laravel

location / {
    proxy_pass       http://127.0.0.1:8300;
    proxy_redirect   http://127.0.0.1:8300/ /;
    proxy_read_timeout 60s;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
15
Jul
2017

Install Xdebug for PHP Ubuntu

15 Jul 2017

Prepare to install:

apt install php7.0-xdebug
php --version

Find xdebug path (latest by year):

find / -name 'xdebug.so' 2> /dev/null

Config update vi /etc/php/7.0/fpm/php.ini:

7
Mar
2017

Eloquent

07 Mar 2017

”`php

    $this->products()
        ->select('category_id',
            DB::raw('count(*) as total'))
        ->groupBy('category_id')
        ->get();


    Task::first();
    Task::all();
    Task::get();
7
Mar
2017

Code snippets

07 Mar 2017

Folders should be normal “755” and files, “644”

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

Snippets

”`php // dates Carbon::parse($createdAt)->addSeconds($this->expires)->isPast(); // check if expired

// token
7
Mar
2017

Console Laravel

07 Mar 2017

”`bash

// Phpunit

 ./vendor/bin/phpunit

php artisan make:test CategoryTest --unit

// Scaffolding

php artisan make:model Post -m
php artisan make:seed PostTableSeed
9
Jun
2015

apidoc

09 Jun 2015

Useful tool apidoc. Setup:

apt update
apt nodejs
apt install nodejs-legacy
apt install npm
npm install apidoc -g

Now check with command apidoc -h.

If everything is alright:

16
Apr
2015

Yii 2 snippets

16 Apr 2015

php yii migrate/create create_user_table php yii migrate/up Yii::$app->request->baseUrl Url::toRoute

$query->from('given t')
    ->leftJoin('given_product as rp','t.id = rp.issuance_id')
    ->leftJoin('product as p','p.id = rp.product_id')
    ->where(['p.status'=>Product::STATUS_GIVEN]);


SET FOREIGN_KEY_CHECKS = 0;