I've read about repository pattern.So, I created UserRepositoryInterface.php file
namespace App\Interfaces;
use Prettus\Repository\Contracts\RepositoryInterface;
interface UserInterface extends RepositoryInterface
{
// Code
}
Then I created UserRepository.php:
<?php
namespace App\Repositories;
use Prettus\Repository\Eloquent\BaseRepository;
use App\Interfaces\UserInterface;
class UserRepository extends BaseRepository implements UserInterface
{
public function model()
{
return User::class;
}
}
Finally, I bind interface to class in RepositoryServiceProvider.php
public function boot()
{
$this->app->bind(UserInteface::class, UserRepository::class);
}
When inject repository to class, I wonder that should I inject with UserRepository or UserInterface. I've read that UserInterface should be injected, but I don't understand why we not just using UserRepository, it can be faster, isn't it?
Someone help?
Thanks.