This episode is for members only

Sign up to access "Enums in Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
08. Recap

Transcript

00:00
let's go ahead and do a quick recap just to reiterate why we've used enums here in place of either plain strings or enums in our database now over in our database here we know that the status can be one of a few pre-selected options we chose to not implement this at a database level
00:19
so we had an enum inside of our app which we could also use for things like validation so when we went ahead and stored a order we validated this against the order statuses that we had predefined in this backed enum it's a backed enum because each of these cases has values what we did then over on the form itself both on create and edit is used our enum values to iterate
00:46
through and build up the ui we did this in two places which means that our enum is a really good candidate already because it means that the more options that we add to this enum that's shown in the ui everywhere and it's also shown or validated everywhere as well so you can see here we've got a new value which we can create and that's perfectly valid to be put into the database
01:07
we then went ahead and implemented a label on our enum so we could show a nice ui value to the user rather than just relying on the single value itself we also then went over to the order model and we implemented a getter or an accessor for the status itself so when we tried to access the status from a model we didn't get back just a plain string value we got back an enum itself
01:34
which means that what we could have then done is gone ahead and used the label again when we're retrieving this value from the database so hopefully the course gave you a good insight into how to use enums in laravel if you have multiple values that could be inserted into your database columns
9 episodes 31 mins

Overview

Enums make working with multiple potential column values a breeze (think order statuses). Let's use an Enum in Laravel and cover storing, validating and accessing Enums.

By the end of the course, you'll be able to implement Enums in Laravel with ease, and make sure your multiple choice column data is strict and easy to globally update across your entire application.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.