// 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
// 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
// parse string
let will_end = '2019-02-01 10:00:00';
let then = moment(new Date(will_end));
// diff in seconds
let then = moment().add(1, 'minute');
let now = moment();
then.diff(now, 'seconds'); // 60
now.diff(then, 'seconds'); // -60
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"
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"
xdebug.overload_var_dump=off
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
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
How to make dynamic class name:


Plugins
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;
}
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;
}
location ~ \.php$ {
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;
}
Config
{
"applications": {
"laravel": {
"type": "php 7.0",
"user": "nobody",
"group": "nobody",
"workers": 2,
"root": "/var/www/vhosts/laravel/public",
"script": "index.php",
},
},
"listeners": {
"*:8300": {
"application": "laravel"
}
}
}
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:
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:
zend_extension="/usr/lib/php/20160303/xdebug.so"
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.overload_var_dump=off
xdebug.idekey = PHPSTORM
xdebug.max_nesting_level = 512
xdebug.file_link_format = phpstorm://open?%f:%l
Then restart:
service php7.0-fpm restart
”`php
$this->products()
->select('category_id',
DB::raw('count(*) as total'))
->groupBy('category_id')
->get();
Task::first();
Task::all();
Task::get();
$this->products()
->select('category_id',
DB::raw('count(*) as total'))
->groupBy('category_id')
->get();
Task::first();
Task::all();
Task::get();
Task::pluck('body');
Task::where('disabled', 1);
Task::selectRaw('year(created_at) year, monthname(created_at) month, count(*) active')->group_by('year', 'month')->get();
Source::leftJoin('site_target_sources', 'site_sources.id', '=', 'site_target_sources.source_id')
->leftJoin('site_targets', 'site_targets.id', '=', 'site_target_sources.target_id')
->where('site_targets.entity_id', $entity->id)
->groupBy('site_sources.id')
->get(['site_sources.*']);
#############################
# PRIMARY KEY
############################
public $primaryKey = 'admin_id';
public $increments = false;
#############################
# RELADTIONS
############################
public function comments()
{
return $this->hasMany('App\Comment');
}
public function user()
{
return $this->belongsTo('App\User');
}
public function phone()
{
return $this->hasOne('App\Phone');
}
#############################
# SCOPES
############################
// ------------
Task::incomplete();
public static function incomplete(){
return static::where('completed', 0)->get();
}
// ------------
Task::incomplete()->where('other', 1)->get();
public function scopeIncomplete($query){
return $query->where('completed', 0);
}
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
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
// dates
Carbon::parse($createdAt)->addSeconds($this->expires)->isPast(); // check if expired
// token
$token = app('auth.password.broker')->createToken($user); // create token manually
// optional
optional($user)->name
”`bash
// Phpunit
./vendor/bin/phpunit
php artisan make:test CategoryTest --unit
// Scaffolding
php artisan make:model Post -m
php artisan make:seed PostTableSeed
// Phpunit
./vendor/bin/phpunit
php artisan make:test CategoryTest --unit
// Scaffolding
php artisan make:model Post -m
php artisan make:seed PostTableSeed
php artisan migrate:refresh --seed
php artisan make:controller PostController --model=Model\\Site\\Post
php artisan view:clear
// Dusk
composer require laravel/dusk
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:
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:
apidoc -i app/Http/Controllers/ -o ~/Projects/theproject-docs
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;
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;
TRUNCATE table1;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE article;
TRUNCATE brand;
TRUNCATE category;
SET FOREIGN_KEY_CHECKS = 1;