Spaces:
Running
Running
feat(membership): admin-driven account creation, real estate tier/investment work, in-progress monorepo migration state
b2dcf0f | namespace App\Infrastructure\Database; | |
| use Illuminate\Database\Query\Builder; | |
| use Illuminate\Support\Carbon; | |
| use Illuminate\Support\Facades\DB; | |
| abstract class BaseRepository | |
| { | |
| abstract protected function table(): string; | |
| protected function query(bool $includeDeleted = false): Builder | |
| { | |
| $query = DB::table($this->table()); | |
| if (! $includeDeleted && $this->hasDeletedAtColumn()) { | |
| $query->whereNull('deleted_at'); | |
| } | |
| return $query; | |
| } | |
| protected function insert(array $attributes): bool | |
| { | |
| $now = Carbon::now(); | |
| return DB::table($this->table())->insert(array_merge([ | |
| 'created_at' => $now, | |
| 'updated_at' => $now, | |
| ], $attributes)); | |
| } | |
| protected function hasDeletedAtColumn(): bool | |
| { | |
| static $cache = []; | |
| return $cache[$this->table()] ??= DB::getSchemaBuilder()->hasColumn($this->table(), 'deleted_at'); | |
| } | |
| } | |