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