Created
September 15, 2015 01:45
-
-
Save fxcosta/47bce19f0e8dd0960d26 to your computer and use it in GitHub Desktop.
Repository Pattern in Laravel 5.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Repositories\MovieRepositoryInterface; | |
use Illuminate\Http\Request; | |
use App\Http\Requests; | |
use App\Http\Controllers\Controller; | |
class MovieController extends Controller | |
{ | |
protected $movieRepository; | |
/** | |
* Display a listing of the resource. | |
* | |
* @return Response | |
*/ | |
public function index(MovieRepositoryInterface $movieRepository) | |
{ | |
$this->movieRepository = $movieRepository; | |
$this->movieRepository->getMoviesByName("Ação"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entities; | |
use Illuminate\Database\Eloquent\Model; | |
use Prettus\Repository\Contracts\Transformable; | |
use Prettus\Repository\Traits\TransformableTrait; | |
class Movie extends Model implements Transformable | |
{ | |
use TransformableTrait; | |
protected $fillable = []; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Repositories; | |
use Prettus\Repository\Eloquent\BaseRepository; | |
use Prettus\Repository\Criteria\RequestCriteria; | |
use App\Entities\Movie; | |
/** | |
* Class MovieRepositoryEloquent | |
* @package namespace App\Repositories; | |
*/ | |
class MovieRepositoryEloquent extends BaseRepository implements MovieRepository | |
{ | |
/** | |
* Specify Model class name | |
* | |
* @return string | |
*/ | |
public function model() | |
{ | |
return Movie::class; | |
} | |
/** | |
* Boot up the repository, pushing criteria | |
*/ | |
public function boot() | |
{ | |
$this->pushCriteria( app(RequestCriteria::class) ); | |
} | |
public function getMoviesByName($name) | |
{ | |
echo $name; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Repositories; | |
use Prettus\Repository\Contracts\RepositoryInterface; | |
/** | |
* Interface MovieRepository | |
* @package namespace App\Repositories; | |
*/ | |
interface MovieRepository extends RepositoryInterface | |
{ | |
public function getMoviesByName($name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment