mirror of
https://github.com/koel/koel
synced 2024-12-22 10:33:16 +00:00
* Use ADMIN_* variables if available to create the admin account * Add APP_MEDIA_PATH for media directory * Use the standard --no-interaction flag to koel:init * Undo variable aligment and code formatting * Prefer early return over else, add new line before return statements * Some fixes
45 lines
1 KiB
PHP
45 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
use Exception;
|
|
use Illuminate\Contracts\Auth\Guard;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Collection;
|
|
|
|
abstract class AbstractRepository implements RepositoryInterface
|
|
{
|
|
/** @var Model */
|
|
protected $model;
|
|
|
|
/** @var Guard */
|
|
protected $auth;
|
|
|
|
abstract public function getModelClass(): string;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->model = app($this->getModelClass());
|
|
|
|
// This instantiation may fail during a console command if e.g. APP_KEY is empty,
|
|
// rendering the whole installation failing.
|
|
try {
|
|
$this->auth = app(Guard::class);
|
|
} catch (Exception $e) {}
|
|
}
|
|
|
|
public function getOneById($id): ?Model
|
|
{
|
|
return $this->model->find($id);
|
|
}
|
|
|
|
public function getByIds(array $ids): Collection
|
|
{
|
|
return $this->model->whereIn($this->model->getKeyName(), $ids)->get();
|
|
}
|
|
|
|
public function getAll(): Collection
|
|
{
|
|
return $this->model->all();
|
|
}
|
|
}
|