Adding Post Columns 0:00Let's add some more fields to our post resource. So I want to add a couple of new columns to the database first. So let's create a migration for the posts table. Let's just call it add more post columns. And then open the migration, and here we're going to add a new datetime column, which will be called publishAt, so that we can store the datetime when this specific post will be available. This can be null. Then we have the same thing for a publishUntil, so that we can define an endDate. Then I want to have a boolean that indicates whether or not the post is actually published.Then we have the same thing for a publishUntil, so that we can define an endDate. Then I want to have a boolean that indicates whether or not the post is actually published. So let's call it isPublished, with the default value of false. So maybe you have some drafts in our database, so that when someone is working on a post, we don't want it to be visible on the website at all. And let's store a string, which will be a category. And also this will be nullable. Okay, let's migrate this. Now we need to add these new columns as fields to our post resource. So if we head back to our post resource, we still have these two fields for the title Adding DateTime Fields 1:39Now we need to add these new columns as fields to our post resource. So if we head back to our post resource, we still have these two fields for the title and for the body. If you want to see a list of all the fields and field types that are available in Nova, you can check it out on the official website, which is at nova.laraval.com, and there you can go to the documentation. And here we have fields and field types. So these are all the available field types that you can choose from in Nova. So what we need now is a DateTime field. So it's just DateTime, Make, and then give it a name.So what we need now is a DateTime field. So it's just DateTime, Make, and then give it a name. All right, so in our case, it would be DateTime, Make, PublishAd. So the way this works with Nova is that it uses the title that you give it, and it will transform it into snake case. So it will end up something like PublishAd. If you don't want to follow this convention, you can also change this. So for example, if we want this field to say PublishPostAd, then we can define the column name as a second parameter and say PublishAd. So this way Nova knows that this field is called PublishPostAd, and it references thename as a second parameter and say PublishAd. So this way Nova knows that this field is called PublishPostAd, and it references the database column PublishAd. But I think PublishAd is fine. And we have another DateTime field, which is called PublishUntil. And be sure to import these DateTime classes. Okay, now if I go back to Nova, and to the Nova site, and let's edit this post again, then we now have these new fields available. So we have the PublishAd and the PublishUntil. And if we click on it, we now have this calendar view where we can just pick a date, and after Casting DateTime Attributes 3:45So we have the PublishAd and the PublishUntil. And if we click on it, we now have this calendar view where we can just pick a date, and after that we can change the time. So let's fill in some values and update the post. Okay, now we get an error that the DateTime fields must cast to DateTime inside of our Eloquent model. So let's fix this by going to our post model. And let's just add casts. So we tell Laravel that our PublishAd field will be casted to DateTime. And the PublishUntil field will also be casted to DateTime.So we tell Laravel that our PublishAd field will be casted to DateTime. And the PublishUntil field will also be casted to DateTime. Alright, so refresh again. And now it works. So now Laravel and Nova knows that these fields are actually DateTimes and they're just some random strings. Okay, great. So if I now edit them back, we have the values that we stored available in here. If I go back to my index and to the listing, we also can see these two date fields here. Alright, let's add the other columns. Adding Published Checkbox 4:53If I go back to my index and to the listing, we also can see these two date fields here. Alright, let's add the other columns. So what else we wanted to do is have some like boolean values. So we need a checkbox. So if we go back to the field types, we can see that we have a boolean field available. Great, that's what we're looking for. So it's just boolean, make, and then give it the title. Alright, so go back to our post. So we have boolean, make, and then it's called isPublished. Store this, import the class.So we have boolean, make, and then it's called isPublished. Store this, import the class. And if we go back and edit this, we now have this checkbox. So let's check it, update the post. Now we see, okay, this is green, yes, this post is published. And if we go back to our listing, we also see it is published. And if we edit again, remove the checkbox, update, it now turns red. And also on the listing, it's now red. Cool. So the last thing I wanted to do is add a category. Adding Category Select 6:11Cool. So the last thing I wanted to do is add a category. And well, I think the nicest way would be that we have some sort of drop-down where a user can select from some pre-existing values that we offer as categories for these posts. So for this, Nova has a field called select. So we can do select, make, category, and then just pass it options, will be an array. So maybe our blog posts have either the category tutorials, and another category could be news. So this is just the key value pair, which will also be used when we store this field. So import the class again. And now if I refresh, we now have a drop-down category with these fields available.So import the class again. And now if I refresh, we now have a drop-down category with these fields available. Let's pick tutorial for this one, update the post. And if we go back here, we now see that we have the category which is tutorials. So this is the value that we stored in the database. Now well, I don't think we should show the publish add and the publish until fields on this listing, it makes it a bit cluttered. So let's get rid of them in the listing. To modify where the Nova fields will be visible, and also where the fields can be edited and created, we can call additional method calls on these field classes. Controlling Field Visibility 7:50To modify where the Nova fields will be visible, and also where the fields can be edited and created, we can call additional method calls on these field classes. So for example, if we want our publish add and publish until fields to only be visible on the edit, create, and detail view, we can do something like hide from index. Add this to both of the fields. And if we now go back, the fields no longer exist in the listing. But if we look at this on the detail page, we can still see that those fields are here. And if we edit them, we can also still see them. You can also define, for example, that you want certain fields to not be visible when you update the post or create the post.You can also define, for example, that you want certain fields to not be visible when you update the post or create the post. So let's say, once the category was selected, we no longer want this to be editable. We can do this by going to the category field. And here we say, hide when updating. So when we update this resource, we don't want this field to be visible. So if we refresh, this is the edit route. We are no longer able to update this category, but we still see it in the listing. And if we create a new post, we can select it. So this way you can control where your fields should be visible and where your users shouldAnd if we create a new post, we can select it. So this way you can control where your fields should be visible and where your users should be able to manipulate the values of these fields. There are a lot more available. So if you go to the documentation and go to showing, hiding fields, there is a lot where you can choose from, so that you can only see fields from the index page, only on the details, only on forms, not on forms, etc. etc. and a lot of combinations. So with just a few lines of code, you can create new fields to your resources and control where these fields should be visible.where these fields should be visible.