You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
trait BelongsToUser
|
||||
{
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user