title: Repository Pattern on Laravel
body: <p>I would like to use the <code>Repository Pattern</code> but I am stuck on the syntax. I want to get my function index().</p>
  
  <p>First step, I create my folder <code>Repositories</code> and I create the file <code>AuteurRepository.php</code></p>
  
  <p><a href="https://i.stack.imgur.com/w1A0D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w1A0D.png" alt="enter image description here"></a></p>
  
  <p>In my file <strong>AuteurController</strong> I have this:</p>
  
  <pre><code>public function index()
  {
     $auteurs = Auteur::oldest()-&gt;paginate(5);
     return view('admin.auteurs.index', compact('auteurs'))
             -&gt;with('i', (request()-&gt;input('page', 1)-1)*5);
  }
  </code></pre>
  
  <p>And in my <strong>Model</strong> I only have a file <strong>Auteur</strong> </p>
  
  <pre><code>protected $fillable = ['name', 'firstname'];
  </code></pre>
  
  <p>I have 2 questions: </p>
  
  <p>1) In my file <strong>AuteurRepository</strong> how should I create my function <strong>index()</strong>? </p>
  
  <p>I have tried this ?</p>
  
  <pre><code>&lt;?php 
  
  namespace App\Repositories; 
  use App\Auteur; 
  
  class AuteurRepository
  {
      public function index()
      {
          return Auteur::oldest()-&gt;paginate(5);
      }
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>My second question is in my <strong>AuteurController</strong> I don't understand what to do ? </p>
  
  <p>I have this for now </p>
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Auteur;
  use App\Repositories\AuteurRepository; 
  
  class AuteurController extends Controller
  {
  
  
      protected $auteurs;
  
      public function __construct(AuteurRepository $auteurs)
      {
          $this-&gt;auteurs = $auteurs; 
      }
  
      public function index(Request $request)
      {
  
          return view('admin.auteurs.index', compact('auteurs'))
      }
  }
  </code></pre>