Adding Field Validation 0:00Let's take a look at validation of our resources. So if we use our post model, or our post resource, and want to create a new one, we don't have any validation in place right now. So with all fields empty, I can just click create post. And well, obviously, we now get an error from our database, because the title column cannot be null. So how can we add validation to our resource fields? If we go to Sublime, and check out our post resource, and then go to the fields, we can just define on every of these fields, the specific rules for this field. So for example, for the title, we can say rules.just define on every of these fields, the specific rules for this field. So for example, for the title, we can say rules. And this will be an array of all the rules that we want to apply. So for example, required. Now if we go back and save this again, we now see this error, the title field is required. And if you don't want to use an array, you can also use the string format that you might use in your form requests, or in your Laravel validator. So you can also use required, and then pass additional rules as comma separated parameters to the rules method. Okay, so we want the title to be required. Defining Post Rules 1:30to the rules method. Okay, so we want the title to be required. The body is also a required rule. Our publishAt, we want this to be after or equal today. And our publishUntil needs to be after or equal of the publishAt field, because it doesn't make sense to publish a post until a time that is before the value of the publishAt. Okay, so the category is also going to be a required field. And our user relationship will also be required. So let's see how this looks like in Chrome. If I try to create another post, we now see all these validation errors. Testing Validation in Nova 2:33So let's see how this looks like in Chrome. If I try to create another post, we now see all these validation errors. So let's just fill it out. So this needs to be today. The publishUntil needs to be something after the publishAt field. So let's use this. We need a category, and we need a user. Let's create it. Okay, now the post was successfully created, because it passed our validation rules. If we take the user resource as an example, we have slightly different validation rules. Creation vs Update Rules 3:03Okay, now the post was successfully created, because it passed our validation rules. If we take the user resource as an example, we have slightly different validation rules. So for example, when we create a new user, we have to enter the password. So it is a required field. But when we edit an existing user, we do not need to provide a password. So how does this work with Nova? And if we take a look at the user resource, we can see that you can not only pass rules, but you can also specify creation rules. So these rules are only applied to whenever a resource is being created. And you can have update rules.So these rules are only applied to whenever a resource is being created. And you can have update rules. And these rules are only applied when you update this specific resource. So for the password example, we don't have any generic rules. But when we create a new user resource, this one will be required, it needs to be a string of minimum six characters. And when we update the password, it can be null. But if it exists, it still needs to be a string with a minimum length of six characters. So just like this, you can specify all your generic rules, your creation and update rules for all your different resource fields in Laravel Nova.So just like this, you can specify all your generic rules, your creation and update rules for all your different resource fields in Laravel Nova.