Skip to content

Instantly share code, notes, and snippets.

@lfbn
Last active July 31, 2020 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfbn/336a01cd003f01121ab5be381cfb63ad to your computer and use it in GitHub Desktop.
Save lfbn/336a01cd003f01121ab5be381cfb63ad to your computer and use it in GitHub Desktop.
BaseRepository.php #laravel #laravel_repositories
<?php
namespace App\Repositories\Eloquent;
use Illuminate\Database\Eloquent\Model;
/**
* Class BaseRepository
* @package App\Repositories\Eloquent
*/
class BaseRepository implements EloquentRepositoryInterface
{
/**
* @var Model
*/
protected $model;
/**
* BaseRepository constructor.
*
* @param Model $model
*/
public function __construct(Model $model)
{
$this->model = $model;
}
/**
* @param array $attributes
*
* @return Model
*/
public function create(array $attributes): Model
{
return $this->model->newModelQuery()->create($attributes);
}
/**
* @param $id
* @return Model
*/
public function find($id): ?Model
{
return $this->model->newModelQuery()->find($id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment