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 ```
17
Feb
2017

Laravel PhpStorm

17 Feb 2017
composer require barryvdh/laravel-ide-helper Add to file `app/config/app.php` in `Application Service Providers` section Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class, Enable in (config/ide-helper.php) 'include_fluent' => true, 'include_helpers' => true, Then php artisan ide-helper:generate php artisan ide-helper:meta php artisan ide-helper:models Script to composer.json "scripts":{ "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan ide-helper:generate", "php artisan ide-helper:meta", "php artisan optimize" ] },
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;