First Commit
This commit is contained in:
commit
610aa1e202
4204 changed files with 636764 additions and 0 deletions
68
app/Repositories/BaseRepository.php
Normal file
68
app/Repositories/BaseRepository.php
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue