Skip to content

Conversation

@aajhiggs
Copy link

I have found use case where I could do with the key of the error array exposed (proposing :key).

If I echo out my errors, on some occasions I output the errors in a single block then treat them using JS (usually moving them to an element on the page by the ID stored in a data attribute).

If I want to print

  • :message
  • , I cannot currently access the :key part (where :key is the ID of the associated field).

    Being able to do this (as adjusted) allows a user to identify exactly what field an individual message was associated with e.g. when using ->all(), and is a simple exposure of data already held in the object.

    Example:

    Format:

    <li data-key=":key">:message</li>
    
    <ul class="errors">
        <li data-key="item_firstname">You didn't enter your first name</li>
    </ul>
    

    I have a use case where I could do with :key exposed.
    
    If I echo out my errors, on some occasions I output the errors in a single block then treat them using JS (usually moving them to an element on the page by the ID stored in a data attribute).
    
    If I want to print <li data-key=":key">:message</li>, I cannot currently access the :key part (where :key is the ID of the associated field).
    
    Being able to do this (as adjusted) allows a user to identify exactly what field an individual message was associated with e.g. when using ->all(), and is a simple exposure of data already held.
    @franzliedke
    Copy link
    Contributor

    Please take into account Laravel's coding standards:

    • spaces between array elements
    • the variable name should be $messagesKey

    Updates following comments by franzliedke
    @aajhiggs
    Copy link
    Author

    @franzliedke I think corrected it as I understand from what you've said. Apologies for the basic error, still getting to grips with keeping my work super neat!

    @bencorlett
    Copy link
    Contributor

    Are you able to provide a couple of tests for this?

    I think this is pretty sweet :)

    @daylerees
    Copy link
    Contributor

    +1 to @bencorlett it would be nice to have some tests. Let's try and keep the code coverage for L4 as high as possible shall we chaps?

    @taylorotwell
    Copy link
    Member

    Done. I added tests.

    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.

    5 participants