I'm writing a new project with laravel 5.1, and I want to use the repository pattern, but I can't figure out what is the best way of doing that.
I was thinking about:
public function save(User $user) { $user->save(); } public function find($id) { return User::find($id); } And then
$user = new User(); $user->email = '[email protected]'; $userRepo->save($user); That way I work with the model as DTO, and it's super easy and comfortable, but then I will be depend on Eloquent.
So I was thinking of using an array instead of model, like that:
public function save(array $user) { User::save($user); } public function find($id) { return User::find($id)->toArray(); } But then it will be much less comfortable to use.
Can you explain me what is the best way of using repository in Laravel so I will be able to change data source easily in the future, but it will still be comfortable to use this pattern?
DTO.