dbp/relay-base-person-bundle
Installation
composer require dbp/relay-base-person-bundle
Publish the bundle’s configuration (if needed):
php artisan vendor:publish --provider="Dbp\RelayBasePersonBundle\RelayBasePersonBundle" --tag="config"
First Use Case: Querying a Base Person
The bundle provides a PersonRepository for querying base person records. Inject it into a service or controller:
use Dbp\RelayBasePersonBundle\Repository\PersonRepository;
class PersonController extends Controller
{
public function __construct(private PersonRepository $personRepository) {}
public function show(int $id)
{
$person = $this->personRepository->find($id);
return response()->json($person);
}
}
Key Configuration
Check config/relay_base_person.php for:
activePersonsOnly).First Query Fetch all active persons with pagination:
$persons = $this->personRepository->newQuery()
->active()
->paginate(10);
Repository-Based CRUD
The bundle follows a repository pattern. Extend PersonRepository for custom logic:
namespace App\Repositories;
use Dbp\RelayBasePersonBundle\Repository\PersonRepository as BasePersonRepository;
class CustomPersonRepository extends BasePersonRepository
{
public function findByEmail(string $email)
{
return $this->newQuery()->where('email', $email)->first();
}
}
Event-Driven Extensions
Listen to bundle events (e.g., PersonCreated) to hook into workflows:
use Dbp\RelayBasePersonBundle\Event\PersonCreated;
Event::listen(PersonCreated::class, function (PersonCreated $event) {
// Send welcome email, log activity, etc.
});
GraphQL Integration If using Relay (GraphQL), the bundle provides base types. Extend them in your schema:
type Person implements Node {
id: ID!
name: String!
# ... extend with custom fields
}
API Resource Transformation
Use PersonResource (if provided) to shape API responses:
use Dbp\RelayBasePersonBundle\Http\Resources\PersonResource;
return PersonResource::collection($persons);
vendor/dbp/relay-base-person-bundle/migrations for reference.PersonFactory (if available) for seeding tests:
$person = PersonFactory::new()->create();
remember() method:
$person = $this->personRepository->remember(3600)->find($id);
Namespace Collisions
The bundle uses Dbp\RelayBasePersonBundle namespace. Avoid naming conflicts with:
use Dbp\RelayBasePersonBundle as RelayPerson;
Missing Documentation
docs-dev/README.md may lack examples for complex extensions. Refer to the Relay docs for GraphQL-specific patterns.src/ for undocumented features (e.g., custom query builders).AGPL License Implications
Query Performance
eagerLoad('*') on large datasets. Use explicit relationships:
$person = $this->personRepository->with(['address', 'roles'])->find($id);
Enable Query Logging
Add to config/logging.php:
'channels' => [
'query' => [
'driver' => 'single',
'path' => storage_path('logs/query.log'),
'level' => 'debug',
],
],
Then log queries in repositories:
\DB::enableQueryLog();
$this->newQuery()->get();
\Log::debug('Queries:', \DB::getQueryLog());
Common Errors
config/relay_base_person.php matches your schema.php artisan cache:clear
Custom Fields Add fields via migrations or entity extensions:
// app/Extensions/PersonExtension.php
namespace App\Extensions;
use Dbp\RelayBasePersonBundle\Entity\Person;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class PersonExtension
{
#[ORM\Column(type: 'string', nullable: true)]
private ?string $customField = null;
// Getters/setters...
}
Override Services
Bind custom implementations in config/app.php:
'bindings' => [
Dbp\RelayBasePersonBundle\Repository\PersonRepository::class => App\Repositories\CustomPersonRepository::class,
],
Add Validation
Extend the Person entity with Symfony Validator constraints:
use Symfony\Component\Validator\Constraints as Assert;
#[Assert\Email]
private ?string $email = null;
Localization
Override translation files in resources/lang/ to customize labels (e.g., relay_base_person.validation.email).
How can I help you explore Laravel packages today?