8000 GitHub - cyrildewit/repository-pattern-laravel: My way of implementing the repository pattern in Laravel 5.*
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

cyrildewit/repository-pattern-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Edit: For everyone who is considering to apply the repository pattern in Laravel. I have stepped away from it, since Eloquent ORM already kind of acts as a repository.

Repository Pattern in Laravel 5.* example

In this git repository you'll find some code examples of my implementation of the repository pattern in Laravel

The place where you should create a repository is inside the App\Repositories folder.

Every repository should be registerd inside a Service Provider. To keep it simple, I placed this inside the AppServiceProvider.php file.

Future

I'm considering about creating a package to simplify the use of my way of implementing the repository pattern. This package will only contain some abstract base classes.

Using a Repository in your Controllers

// App/Controllers/CoursesController.php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Repositories\Course\CourseRepositoryInterface;

class CoursesController extends Controller
{
    /** @var \App\Repositories\Course\CourseRepositoryInterface */
    protected $courseRepository;

    /**
     * Constructor function of CoursesController
     *
     * @return void
     */
    public function __construct(CourseRepositoryInterface $courseRepository)
    {
        $this->courseRepository = $courseRepository;
    }
    
    /**
     * Returns the courses catalog page.
     *
     * @return \Illuminate\View\View
     */
    public function index()
    {
        $courses = $this->coursesRepository->getAll();
        
        return view('courses.index', [
            'courses' => $courses,
        ]);
    }
}

About

My way of implementing the repository pattern in Laravel 5.*

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

0