$this->app->singleton(UserRepositoryContract::class, function () {
return new UserRepository(
new User()
);
});
class UserController extends Controller
{
private $userService;
public function __construct(UserService $userService)
{
$this->userService = $userService;
}
public function index(){
$users = $this->userService->getAllUsersForAdmin(12);
return view('admin.users.index', compact('users'));
}
}
class UserService
{
private $userRepository;
public function __construct()
{
$this->userRepository = app(UserRepositoryContract::class);
}
public function getAllUsersForAdmin($perPage){
return $this->userRepository->getAllUsersForAdmin($perPage);
}
}
class UserRepository implements UserRepositoryContract
{
private $user;
public function __construct($user)
{
$this->user = $user;
}
public function getAllUsersForAdmin($perPage)
{
return $this->user->paginate($perPage);
}
}
public function __construct(UserRepository $userRepository)
{
$this->userRepository = userRepository;
}
public function __construct()
{
$this->userRepository = app(UserRepositoryContract::class);
}
и в Observer делать задачу на удаление картинки