UserRepository (interface) & EloquentUser

Posted 1 year ago by omarsow94

Hello , i have "Class App\Repositories\User does not exist" error .

UserRepository class :

<?php

namespace App\Repositories;

use App\User;

interface UserRepository
{
    public function getAll();

    public function getById($id);

    public function create(array $attributes);

    public function update($id, array $attributes);

    public function delete($id);
}

EloquentUser class :

<?php

namespace App\Repositories;

class EloquentUser implements UserRepository
{

  public function __construct(User $model)
  {
     $this->model = $model;
  }
  public function getAll()
  {
    return $this->model->all();
  }

  public function getById($id)
  {
    return $this->findById($id);
  }

  public function create(array $attributes)
  {
    return $this->model->create($attributes);
  }

  public function update($id, array $attributes)
  {
    $user = $this->model->findOrFail($id);
    $user->update($attributes);
    return $user;
  }

  public function delete($id)
  {
    $this->getById($id)->delete();
    return true;
  }
}

AND register function in AppServiceProvider class :

  public function register()
    {
       $this->app->singleton(UserRepository::class , EloquentUser::class);
    }

Please sign in or create an account to participate in this conversation.