PHP code example of ark4ne / laravel-repository

1. Go to this page and download the library: Download ark4ne/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/ */

    

ark4ne / laravel-repository example snippets


use Illuminate\Database\Eloquent\Model;

class Pet extends Model {
    // ...
}

use Ark4ne\Repositories\Contracts\RepositoryContract;

interface PetRepositoryContract extends RepositoryContract {
    //
}

use Ark4ne\Repositories\Eloquent\Repository;

class PetRepository extends Repository implements PetRepositoryContract {
    protected function getModel() : Pet {
        return new Pet;
    }
}

// RepositoryServiceProvider.php

public function register() {
    $this->app->bind(PetRepositoryContract::class, PetRepository::class);
}

// PetController.php

class PetController extends Controller {
    private $repository;
    
    public function __construct(PetRepositoryContract $repository) {
        $this->repository = $repository;
    }
    
    public function store(PetStoreRequest $request) {
        $data = $request->validated();
        
        $pet = $this->repository->store($data);
        
        return new PetResource($pet);
    }
}


count(array<string, null|int|string|Closure> $criteria): int

all(): \Illuminate\Support\Collection

paginate(array<string, null|int|string|Closure> $criteria, int|null $per_page): \Illuminate\Contracts\Pagination\LengthAwarePaginator

find(int|string $id): \Illuminate\Database\Eloquent\Model

findBy(string $field, mixed $value): \Illuminate\Database\Eloquent\Model

findByMany(array<string, null|int|string|Closure> $criteria): \Illuminate\Database\Eloquent\Model

getWhere(string $field, mixed $value): \Illuminate\Support\Collection

getWhereMany(array<string, null|int|string|Closure> $criteria): \Illuminate\Support\Collection

store(array<string, mixed> $data): \Illuminate\Database\Eloquent\Model

update(int|string $id, array<string, mixed> $data): \Illuminate\Database\Eloquent\Model

delete(int|string $id): bool

withCriteria(array<string, null|int|string|Closure> $criteria): self

withRelationships(array<string> $relationships): self