You've already forked Atomcms-edit
65 lines
1.4 KiB
PHP
Executable File
65 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
trait HasCommonScopes
|
|
{
|
|
/**
|
|
* Scope to get active records.
|
|
*/
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->where('active', true);
|
|
}
|
|
|
|
/**
|
|
* Scope to get pending records.
|
|
*/
|
|
public function scopePending(Builder $query): Builder
|
|
{
|
|
return $query->where('status', 'pending');
|
|
}
|
|
|
|
/**
|
|
* Scope to get ordered records.
|
|
*/
|
|
public function scopeOrdered(Builder $query, $column = 'order', $direction = 'asc'): Builder
|
|
{
|
|
return $query->orderBy($column, $direction);
|
|
}
|
|
|
|
/**
|
|
* Scope to get latest records.
|
|
*/
|
|
public function scopeLatest(Builder $query, $column = 'created_at'): Builder
|
|
{
|
|
return $query->orderBy($column, 'desc');
|
|
}
|
|
|
|
/**
|
|
* Scope to get records created today.
|
|
*/
|
|
public function scopeToday(Builder $query, $column = 'created_at'): Builder
|
|
{
|
|
return $query->whereDate($column, today());
|
|
}
|
|
|
|
/**
|
|
* Scope to get records from the last days.
|
|
*/
|
|
public function scopeLastDays(Builder $query, $days, $column = 'created_at'): Builder
|
|
{
|
|
return $query->where($column, '>=', now()->subDays($days));
|
|
}
|
|
|
|
/**
|
|
* Default behavior scope (can be overridden).
|
|
*/
|
|
public function scopeDefaultBehavior(Builder $query): Builder
|
|
{
|
|
return $query;
|
|
}
|
|
}
|