mivita/dev/app-bak/Repositories/BaseRepository.php
2025-10-20 17:42:08 +02:00

68 lines
1.1 KiB
PHP

<?php
namespace App\Repositories;
abstract class BaseRepository {
/**
* The Model instance.
*
* @var Illuminate\Database\Eloquent\Model
*/
protected $model;
/**
* Get number of records.
*
* @return array
*/
public function getNumber()
{
$total = $this->model->count();
$new = $this->model->whereSeen(0)->count();
return compact('total', 'new');
}
/**
* Destroy a model.
*
* @param int $id
* @return void
*/
public function destroy($id)
{
$this->getById($id)->delete();
}
/**
* Get Model by id.
*
* @param int $id
* @return App\Models\Model
*/
public function getById($id)
{
return $this->model->findOrFail($id);
}
/**
* Get Model by id.
*
* @param int $id
* @return App\Models\Model
*/
public function getAll()
{
return $this->model->all();
}
/**
* @return Illuminate\Database\Eloquent\Model
*/
public function getModel()
{
return $this->model;
}
}