This episode is for members only

Sign up to access "Build An Uptime Monitor with Inertia" right now.

Get started
Already a member? Sign in to continue
Playing
34. Site model email notification storage

Episodes

0%
Your progress
  • Total: 4h 59m
  • Played: 0m
  • Remaining: 4h 59m
Join or sign in to track your progress

Transcript

00:00
If you cast your mind back to the introduction, we had this little panel down here that allowed
00:04
us to add emails to alert people when a particular endpoint went down. Now what we're going to do in this video is figure out where's best to store these emails. And actually we're not going to set this up as a relationship with a separate table. Instead what we're going to do is create a JSON column on each of the sites to store
00:24
these emails. There's not really much point in this case setting up an entirely new model, an entirely new database table just to store the emails that we want to send. So we're going to set this up in terms of the migration and the model in this episode
00:38
and then we're going to go over and look at how we add these via the UI. Okay so if we just take a look at the database at the moment, over on our site we've got all of the information that we want. We want another column in here which represents an array of all of the email addresses that
00:54
we want to alert to. So the first thing that we're going to do is go ahead and create our migration to handle this. So let's go ahead and make a migration here and we're going to say add notification emails
01:05
to site table. That should generate all of the scaffolding out that we need. So add notification emails to site table. Let's come down and we have our site schema defined here for us.
01:18
So we're going to go ahead and define out a JSON column called notification emails. We're going to make this nullable and we're going to set a default here of an empty array. So that's enough to get this going. Let's go down here and just define the down migration.
01:38
So table drop column and we're going to go ahead and pop the notification emails in there. So let's migrate this, phpArtisan migrate, and we're good to go. Now that has not worked at the moment so let's just have a look at what has happened here. Okay, yeah, so site does not exist, that's site.
01:56
So let's just change that over, try again, and we're good, great. So now we have a notification emails column. This can contain being an array, an array of different string email addresses. So we could have anything in here like so.
02:14
Now we're going to keep that as an empty array just for now. So let's just discard those changes and let's go over to the model and make sure that this is set up for everything to be cast properly. So we'll go over to site.php and let's go up to the top here.
02:29
The first thing that I'm going to do is just add this into the fillable, so notification emails, and then we're going to make sure that this gets cast to an array when we deal with this data. So we're going to define out a casts property on this model and we're just going to put
02:42
notification emails inside of here. The reason for this is otherwise this value may come back as a string, which is not what we want. We want this to come back as an array so we can iterate through it and do what we need
02:55
with it. Okay, so that is how we are storing our notification emails. In the next episode, we're going to set the UI up and allow email addresses to be added to this array.
44 episodes4 hrs 59 mins

Overview

Ready to dive into Inertia? Let's build a real-world app with Laravel, Inertia and Vue! If you're already working with Inertia, you'll pick up some tips and techniques for future projects.

This uptime monitor allows you to create and switch between sites, then add endpoints to monitor with frequency intervals. Using the power of scheduling and queues, it'll automatically alert the email addresses you've added via the UI when an endpoint goes down.

In this course, you'll learn to:

  • Build a real app from scratch with Inertia
  • Work with Laravel queues
  • Perform actions on models at user-defined intervals
  • Work with sub-minute schedules in Laravel
  • Send out channel notifications with Laravel
  • Use API resources to simplify Inertia data
  • Organise apps with events and observers
  • Create modals in Vue
  • Perform inline editing with Inertia forms
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

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