I'm working in my Laravel 5.4 project with the Repository Pattern (I'm quite new to that pattern). I've red a lot about this on the web but I still have two important questions:
> Question #1:
Imagine I use Laravel ORM Eloquent and I have a interface that looks like this:
<?php namespace App\Repositories\User; interface UserRepoInterface { /** * @param array $user */ public function update(array $request, User $user); } You can see that I have specified the eloquentUser model like a parameter.
The eloquent implementation looks like this:
public function update(array $request, User $user) { $user->name = $request['name']; $user->last_name = $request['last_name']; $user->email = $request['email']; $toUpdate->save(); } So my question:
Is it wrong to hardcode the eloquent User model in my interface? In lots of examples on the web I see people doing this but what If I want to swap the eloquent implementation with a file based implementation? That's a problem because I have to pass a User model to the update method!
What is the solution to this problem should I only declare $user instead of User $user?
> Question #2:
How should I handle pagination?
For example in my eloquent UserRepository I've a method that looks like this:
public function index() { return User::orderBy('name', 'asc') ->withCount('messages') ->with('corporation') ->paginate(10); } Is this wrong? Should I only paginate in my controller?
A good explanation would help me a lot.