loading...

Laravel Design Patterns

github logo ・1 min read

Hello,

I am new to design patterns and would like to implement it to own project. I have the following application structure.

app
  -- Http
    -- Controllers
       ProductController.php
  -- Models
     Product
  -- Repositories
      -- Contracts
         ProductInterface.php
     ProductRepository.php

I need your help to understand with the following.
I want to make my codes extendable like what I have to do If I want to use the Cache for my queries or want to use the Redis?

ProductInterface.php

interface ProductInterface
{
    ...

    public function find($id);

    ...
}

ProductRepository.php

class ProductRepository implements ProductInterface
{
   ...

   public function find($id)
   {
      return $this->product->find($id);
   }

   ...
}

Any example is must appreciated.

twitter logo DISCUSS (1)
Classic DEV Post from Sep 23 '17

You Can't Learn Everything

Utilizing the strengths of multiple people is the only way to escape the trap of being a jack of all trades.

Jogesh profile image

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️