title: API Calls in Laravel Repository Model
body: <p>I am developing a web application in which I will be using third party API integrations (Payment gateways, SMS Vendors, Emailing services like mailchimp, other external APIs). My application will be having the repository pattern which will have repositories associated with each of my models and my controllers will be utilising the repository functions.</p>
  <p>Now where does all my API integrations comes in? Should I be keeping all my API integrations in a single repository?</p>
  <p>Example :</p>
  <p>If I have a SMS provider Valuefirst, how does my Laravel repository design look like?</p>
  <h2>My SMS interface</h2>
  <pre><code>interface ISmsProvider {
      public function sendSms($mobileNo,$msg);
  }
  </code></pre>
  <h2>My ValueFirst (SMS Provider) repository</h2>
  <pre><code>class ValueFirstRepository implements ISmsProvider {
      public function sendSMS($mobieNo,$msg)
      {
         //API Call to ValueFirst SMS provider
         // Any database insertions/updates to SMS model
         // Any file logs
      }
  }
  </code></pre>
  <p>Assuming I have a service provider class where I have done the binding of the interface and repository my controller will look like</p>
  <h2>SMS Controller</h2>
  <pre><code>class SmsController extends BaseController {
      // ISmsProvider is the interface
      public function __construct(ISmsProvider $sms)
      {
          $this-&gt;sms = $sms;
      }
  
      public function sendSMS()
      {
          $mobileNo = '9999999999';
          $msg = 'Hello World!';
          $users = $this-&gt;sms-&gt;sendSMS($mobileNo,$msg); 
      }    
  }
  </code></pre>
  <p>My questions</p>
  <ol>
  <li>Is this the right approach to an API integration using repository pattern?</li>
  <li>Does anything related to any database activities happens in the ValueFirst repository? Eg : If I want to update a record after the API response from ValueFirst, do I do it in the repository?</li>
  <li>If it's right , can someone show me how the model interactions happens from the repository?</li>
  <li>Now if I need to choose between ValueFirst or any other vendor how does that happens? How can I do it from the controller?</li>
  </ol>
  <p>I will be using this project as a skeleton for my application</p>
  <p><a href="https://github.com/andersao/l5-repository" rel="nofollow noreferrer">l5-Repository</a></p>
  <p>Please help me with this design, I am fairly new to Laravel / repository pattern. Trying to learn stuff. TIA :)</p>