Validation
validation, both serverside and clientside, is essential for a satisfactory user experience, and for security.
This application makes use of several forms, so it is important that the site be completely tamper-proof.
Thankfully, Laravel takes helps the cause, with the @csrf tag, which prevents csrf attacks, or cross-site request forgery. (explain this).
validation on the registration is handled largely by the livewire auth package, the only tweak made is validation for the username, which was covered in the auth blog post. which leaves 5 forms to validate:
- create subweddit
- create post
- edit post
- create comment
- create reply
The message can be displayed by calling the array $errors. With our Bulma framework, we can make things look a little prettier for the user by changing the form border to red and displaying the red error message.
1. create subwedddit
In accordance with Reddit.com,
- Subweddit names are required, must be unique, contain no spaces (much like usernames), with a max character count 20.
- Bio is required, and can have a max char count of 64,000
- The logo must be an image, with an image mime type such as jpg, png or gif (laravel automatically detects the mime type, smart!)
The request can be validated in the store method by laravel's validate() function like so:
2. create post
create post is very similar to creating a subweddit except
- A post can have a longer character limit, at 255
- an image is not required, a post can simply have a title and body
Comments
Post a Comment