Skip to content

Conversation

Klaas058
Copy link
Contributor

Currently when using annotations with database rules like Exists and Unique, it is not possible to include database constraints.

This will throw a php error:

// Error: Constant expression contains invalid operations
#[Exists(Customer::class, column: 'id', where: fn($query) => $query->where('active', true))]
public ?int $customer_id

This feature would allow using database constraints like so:

// Valid php 🎉
#[Exists(Customer::class, column: 'id', where: new WhereConstraint('active', true))]
public ?int $customer_id

After testing this has been working great for us, happy with any feedback

One thing I'm not a 100% sure about:

  • Types in the DatabaseConstraint implementations are mixed since the Laravel methods are untyped themselves. Is this the best way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant