我在这里有一个服务提供商以及http://dfg.gd/blog/decoupling-your-code-in-laravel-using-repositiories-and-services 我的服务提供商:
class UsersRepositoryServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('App\Repositories\Users\UsersInterface', function($app)
{
return new UsersRepository(new User);
});
}
我收到错误:Call to a member function find() on a non-object
我的存储库:
use \Illuminate\Database\Eloquent\Model;
//..
protected $usersModel;
public function __consturct(Model $users)
{
$this->usersModel = $users;
}
/**
* Get user by id
*
* @param mixed $userId
* @return Model
*/
public function getUserById($userId)
{
return $this->convertFormat($this->usersModel->find($userId));
}
答案 0 :(得分:0)
__ consturct拼错了。
正确是__construct