”`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
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
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"
]
},