DEV Community

loading...

Laravel Design Patterns

jogeshpi03 profile image Jogesh ・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.

Discussion

pic
Editor guide
Collapse
mkimont profile image
Matt Kimek

Turn it on in config and it will cache automatically