1. Go to this page and download the library: Download tlikai/laravel-repository library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tlikai / laravel-repository example snippets
namespace App\Repositories;
use Uniqueway\Repositories\Contracts\RepositoryInterface;
use Uniqueway\Repositories\Eloquent\Repository;
class FilmsRepository extends Repository {
public function model() {
return 'App\Film';
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
class Film extends Model {
protected $primaryKey = 'film_id';
protected $table = 'film';
protected $casts = [
"rental_rate" => 'float'
];
}
namespace App\Http\Controllers;
use App\Repositories\FilmsRepository as Film;
class FilmsController extends Controller {
private $film;
public function __construct(Film $film) {
$this->film = $film;
}
public function index() {
return \Response::json($this->film->all());
}
}
public function all($columns = array('*'))
public function lists($value, $key = null)
public function paginate($perPage = 1, $columns = array('*'))
public function save($model)
public function delete($model)
public function find($id, $columns = array('*'))
public function findBy($field, $value, $columns = array('*'))
public function findAllBy($field, $value, $columns = array('*'))
public function findWhere($where, $columns = array('*'))
public function findWhereIn($field, $values, $columns = ['*'])
public function whereHas($relation, $closure)
public function apply($model, Repository $repository)
$this->film->find($id);
$film = new Film;
$film->fill($attributes);
$this->film->save($film);
namespace App;
use Illuminate\Database\Eloquent\Model;
class Film extends Model {
protected $primaryKey = 'film_id';
protected $table = 'film';
protected $casts = [
"rental_rate" => 'float'
];
public function publish()
{
$this->status = 'publish';
}
}
namespace App\Repositories\Criteria\Films;
use Uniqueway\Repositories\Criteria\Criteria;
use Uniqueway\Repositories\Contracts\RepositoryInterface as Repository;
class LengthOverTwoHours extends Criteria {
/**
* @param $model
* @param RepositoryInterface $repository
* @return mixed
*/
public function apply($model, Repository $repository)
{
$model = $model->where('length', '>', 120);
return $model;
}
}
namespace App\Http\Controllers;
use App\Repositories\Criteria\Films\LengthOverTwoHours;
use App\Repositories\FilmsRepository as Film;
class FilmsController extends Controller {
/**
* @var Film
*/
private $film;
public function __construct(Film $film) {
$this->film = $film;
}
public function index() {
$this->film->pushCriteria(new LengthOverTwoHours());
return \Response::json($this->film->all());
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.