Playing
04. Updating an address

Episodes

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

Transcript

00:00
So let's now look at updating one-to-one relationships. And once again, we're going to do this
00:05
within a separate route, just so we can grasp the concept of this before we later go ahead and build our real-world application. So I'm going to go ahead and create out another get route
00:16
here, which would normally be something like put or patch. And we're just going to call this update. Now, inside of here, because we're working with a one-to-one relationship, which,
00:26
to be honest, is pretty rare when you're building an application. We'll talk about that a little bit later. But we want to access that address relationship
00:35
and just update the data. And that will always update the one thing that a user has. Let's demo this out and see what we mean. So once again, because we're not authenticating anywhere,
00:45
we're going to go ahead and find that particular user whose address we want to update. And then we're going to just do the same thing. We're going to access the address relationship
00:54
by its method. And you guessed it, we're going to call the update method. And then we can just pass through any of the specific fields that we want to update.
01:03
We can choose to update one of these columns. We can update all of them at the same time. It really doesn't matter. So we're going to go ahead and update the line 1
01:12
here to be something different. Let's say one eloquent lane, for example. And let's go ahead and run this and see what happens. So obviously, at the moment in the database,
01:22
it's set to 38 code road. Let's head over to the update endpoint we've just created. And then let's head over to the database. And there we go.
01:30
Sure enough, that has been updated. And you'll notice that the updated at date will be changed as well, because we have updated this. This is automatically touched to increment the timestamp
01:41
to the current date and time. Most of the time, we don't reference updated at, but it's a good idea to have it there just so you know when this has been updated.
33 episodes4 hrs 18 mins

Overview

Eloquent is Laravel's ORM (Object Relational Mapper). In simple terms, it's how your models work with the database.

The good news? There's a bunch of powerful relationship types available. Our task is to learn when and where to use each one.

In this course, we'll cover each basic relationship type, how to access related models, and then insert, sync, update and delete related data. Oh, and we'll build a practical example for each relationship type, to really make it stick.

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

Comments

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