PHP code example of miladimos / laravel-repository
1. Go to this page and download the library: Download miladimos/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/ */
miladimos / laravel-repository example snippets
protected $repositories = [
[
TagEloquentRepositoryInterface::class,
TagRepository::class,
],
];
private $tagRepo;
public function __construct(TagEloquentRepositoryInterface $tagRepo)
{
$this->tagRepo = $tagRepo;
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* define your repositories here
*/
protected $repositories = [
[
ModelEloquentRepositoryInterface::class,
ModelRepository::class
],
];
public function register()
{
foreach ($this->repositories as $repository) {
$this->app->bind($repository[0], $repository[1]);
}
}
}
php artisan make:repository:provider
App\Providers\RepositoryServiceProvider::class,
$model->all($columns = ['*']);
$model->create(array $data);
$model->update(array $data, $id, $attribute = "id");
$model->find($id);
$model->findOrFail($id);
$model->findWhere(string $field, $condition, $columns);
$model->first();
$model->last();
$model->firstOrCreate();
$model->whereIn($attribute, array $values);
$model->max($column);
$model->min($column);
$model->avg($column);
$model->delete($id);
$model->truncate();
$model->count($columns = ['*']);
$model->paginate($columns = ['*'], $perPage = 8);
$model->simplePaginate($limit = null, $columns = ['*']);
$model->search(array $query, $columns = ["*"]);
$model->pluck($value, $key = null);
$model->with($relations);
$model->toSql();