Skip to main content

Search Results for "interfaces"

We found 11 results for "interfaces".

Haven't found what you're looking for?

Our team is here to help. Ask us anything about Laravel development and we'll get back to you with personalized guidance.

Ask for Personal Help

We'll respond within 24 hours

Function available only for premium members.

Be as specific as possible so we can provide the best guidance.

Tutorial 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

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.