16
Jan
2018

Carbon & Moment.js

16 Jan 2018
```php // 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 ``` ```js // 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 ```
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" xdebug.overload_var_dump=off
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** How to make dynamic class name: <img src="http://sandra1n.com/screens/2017-09-08_17-16-37-HcmFHwbF.png"> <img src="http://sandra1n.com/screens/2017-09-08_17-19-41-b3AUZDue.png"> **Plugins** https://github.com/bodiam/intellij-bootstrap3
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; } 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" } } }
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`: 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
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(); 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); } ```
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 $token = app('auth.password.broker')->createToken($user); // create token manually // optional optional($user)->name ```
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 php artisan migrate:refresh --seed php artisan make:controller PostController --model=Model\\Site\\Post php artisan view:clear // Dusk composer require laravel/dusk ```
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: apidoc -i app/Http/Controllers/ -o ~/Projects/theproject-docs
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; TRUNCATE table1; SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 0; TRUNCATE article; TRUNCATE brand; TRUNCATE category; SET FOREIGN_KEY_CHECKS = 1;