Skip to content

[Proposal] MessageBag Constructor #84

Closed
@loic-sharma

Description

@loic-sharma

Creating a new instance of a MessageBag and then manually adding each message is tedious. Being able to pass messages in the constructor may be an alternative. For example, currently this needs to be done:

$messages = new MessageBag;

$messages->add('username', 'The username does not exist.');
$messages->add('password', 'Incorrect password.');

Instead, this may be better:

$messages = new MessageBag(array(
    'username' => 'The username does not exist.',
    'password' => 'Incorrect password.',
));

This would also need to support multiple errors for the same key. That would look something like:

$messages = new MessageBag(array(
    'username' => 'The username does not exist.',
    'password' => array(
        'The password is required.',
        'Incorrect password.',
    ),
));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions