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); } ```