Skip to main content

Search Results for "interfaces"

We found 11 results for "interfaces".

Tutorial 4 min read Free

Interfaces in Laravel: Simple Singleton Example of Two Services

When do you need to create interfaces in PHP/Laravel? Suppose you have a method with different implementations depending on some condition. In that case, it may be a candidate for an interface, with different classes implementing that interface method differently, depending on that condition. Let me show an example.

Code Example iluminar/goodwork

iluminar/goodwork

Files in the example:

  • app/Base/Contracts/HasMembers.php
  • app/Office/Models/Office.php
  • app/Project/Models/Project.php
  • app/Team/Models/Team.php

Code Example monicahq/monica

monicahq/monica

Files in the example:

  • app/Interfaces/Hashing.php
  • app/Models/ModelBindingHasher.php
  • app/Traits/Hasher.php

Code Example pterodactyl/panel

pterodactyl/panel

Files in the example:

  • app/Contracts/Repository/TaskRepositoryInterface.php
  • app/Repositories/Eloquent/TaskRepository.php
  • app/Contracts/Repository/RepositoryInterface.php

Code Example stefanzweifel/screeenly

stefanzweifel/screeenly

Files in the example:

  • modules/Screeenly/Contracts/CanCaptureScreenshot.php
  • modules/Screeenly/Services/InMemoryBrowser.php
  • modules/Screeenly/Services/ChromeBrowser.php
  • modules/Screeenly/Providers/ScreeenlyServiceProvider.php
  • modules/Screeenly/Services/CaptureService.php
  • tests/modules/Screeenly/integration/api/v2/ApiV2ScreenshotTest.php