class User extends Model {
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
public function scopeWomen($query)
{
return $query->whereGender('W');
}
}
public function scopeOwner($query, $id)
{
return $query->where('user_id', $id);
}
public static function getTicket($id)
{
$ticket = Support::where('id', $id)->owner(Auth::user()->id)->first();
return $ticket;
}
You can also do this
public static function getTicket($id)
{
$ticket = static::where('id', $id)->owner(auth()->id())->first();
return $ticket;
}
protected static function booted()
{
self::addGlobalScope('latest', function ($query){
$query->latest('updated_at');
});
}
// in your model
public function scopeField($query)
{
return $query->where('field', 'value'); // if in header return $query->where('field', request()->field);
}
// in your controller or repository
public function index()
{
return Package::field()->get();
}
class User extends Model {
protected function getDateFormat()
{
return 'U';
}
}
$users = User::popular()->women()->orderBy('created_at')->get();
public function apply(Builder $builder, Model $model)
{
$builder->where('age', '>', 200);
}
protected static function boot()
{
parent::boot();
static::addGlobalScope(new ArchiveScope);
}