Last active
July 31, 2020 18:18
-
-
Save lfbn/336a01cd003f01121ab5be381cfb63ad to your computer and use it in GitHub Desktop.
BaseRepository.php #laravel #laravel_repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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