This episode is for members only

Sign up to access "Eloquent Relationships By Example" right now.

Get started
Already a member? Sign in to continue
Playing
22. Detaching relations

Episodes

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

Transcript

00:00
Now that we have looked at attaching, we're going to quickly look at detaching. We're not going to go for a practical example here, but you can use what we learned in the last episode to pull this together into your own apps.
00:09
Okay. So let's go ahead and create out a route in here, which will allow us to detach something, and we'll take a look at how we can do this. You probably already guessed how.
00:19
So we know that we want to grab what we want to detach from. So we're going to go ahead and grab the course that we want to detach from. Once again, that's just going to be the same one that we had before. So let's just grab both of these and put them in here.
00:36
So we've got learn inertia and Laravel. I think we don't have anything attached to that just yet, but we can go ahead and use our practical example to do that. Okay.
00:45
So let's make sure we have some actual topics on here first. So let's go and head over to course two. We'll attach Laravel. We'll go ahead and attach eloquent and we'll go ahead and attach inertia.
00:58
It doesn't really make sense, but we have three in here now and we can start to detach these. Okay. So we're going to find a topic Laravel and for a course, we want
01:07
to go ahead and get rid of this. So we're going to say course again, topics, and you probably guessed it, we're going to use detach. So we can pass through either the ID or the actual topic itself to this.
01:19
And that's going to go ahead and remove that for us. So similar UI, if you had a list of them, you could post through to delete these basically. Okay.
01:27
Let's head over and just give the detach page a refresh and see what happens. If we head over, we should see Laravel disappear from this list. And sure enough, we do. So we could do that for all of these if we wanted to, and that would go
01:41
ahead and get rid of each of them. You kind of get the idea. Detach just detaches exactly the same as attach very simple method, but obviously just the opposite.
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.