PHP code example of bigpaulie / repository

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

    

bigpaulie / repository example snippets


class PersonRepository extends AbstractRepository {}

/** @var PersonRepository $repository */
$repository = new PersonRepository();

/** @var Person|null $person */
$person = $repository->find(1);

/** @var PersonRepository */
$repository = new PersonRepository();

/** @var Illuminate\Database\Eloquent\Collection|Person[] */
$persons = $repository->all();

/** @var PersonRepository $repository */
$repository = new PersonRepository();

/** @var Person $person */
$person = $repository->create([
    'name' => 'Popescu Ion',
    'age' => 30
]);

/** @var PersonRepository $repository */
$repository = new PersonRepository();

/** @var Person $person */
$person = $repository->update([
    'name' => 'Popescu Marin',
    'age' => 33
], 1);

/** @var PersonRepository $repository */
$repository = new PersonRepository();

try {
    /** @var Person $person */
    $person = $repository->delete(1);
} catch (RepositoryException $exception) {
    // do something if operation fails
}

/** @var PersonRepository $person */
$personRepository = repository(PersonRepository::class);

/** @var PersonRepository $person */
$personRepository = repository(Person::class);

/** @var bigpaulie\repository\Repository $dog */
$repository = repository(Dog::class);
bash
$ php artisan vendor:publish --provider=bigpaulie\\repository\\RepositoryServiceProvider --tag=repository.config
shell script
php artisan repository:generate Person