Skip to content

Commit ac12229

Browse files
authored
Merge branch '5.next' into 5.next-findorcreate
2 parents 175a41c + 325f776 commit ac12229

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

en/appendices/5-2-migration-guide.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ Datasource
3333
- The ability to cast an ``EntityInterface`` instance to string has been deprecated.
3434
You should ``json_encode()`` the entity instead.
3535

36+
Event
37+
-----
38+
39+
- Returning values from event listeners / callbacks is deprecated. Use ``$event->setResult()``
40+
instead or ``$event->stopPropogation()`` to just stop the event propogation.
41+
3642
View
3743
----
3844

@@ -83,6 +89,13 @@ Database
8389
quote values to be used in SQL queries where prepared statements cannot be
8490
used.
8591

92+
Datasource
93+
----------
94+
95+
- Application rules can now use ``Closure`` to define the validation message.
96+
This allows you to create dynamic validation messages based on the entity
97+
state and validation rule options.
98+
8699
ORM
87100
---
88101

en/orm/validation.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,28 @@ by the ones returned from the rule::
527527
]
528528
);
529529

530+
As of 5.2.0, you can also provide a ``Closure`` for the ``message`` key. When
531+
the validation rule fails, you can create dynamic error messages based on the
532+
entity and options::
533+
534+
$rules->add(
535+
$rules->existsIn('article_id', 'Articles'),
536+
'article_exists',
537+
[
538+
'message' => function ($entity, $options) {
539+
return sprintf(
540+
'Article with ID %s does not exist',
541+
$entity->article_id
542+
);
543+
}
544+
]
545+
);
546+
530547
.. note::
531548

532549
Note that in order for the returned message to be actually used, you *must* also supply the
533550
``errorField`` option, otherwise the rule will just silently fail to pass, ie without an
534-
error message being set on the entity!
551+
error message being set on the entity.
535552

536553
Creating Custom re-usable Rules
537554
-------------------------------

0 commit comments

Comments
 (0)