Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
00:00:00,150 --> 00:00:00,790
All right.
1
00:00:00,790 --> 00:00:03,450
Welcome back my student.
2
00:00:03,600 --> 00:00:08,270
So on this lecture here we are going to be learning about eloquent.
3
00:00:08,310 --> 00:00:14,220
All right which is the functionality of Claribel there is actually one of the most popular ones because
4
00:00:14,220 --> 00:00:22,960
it allows us to do a lot of database queries in a very easy easy format a lot easier than raw as well
5
00:00:22,970 --> 00:00:23,020
.
6
00:00:23,050 --> 00:00:26,250
OK so now how does it work.
7
00:00:26,250 --> 00:00:31,890
This is the part where it gets most confusing in our and I want you to pay very close attention because
8
00:00:31,890 --> 00:00:32,930
you need to get this.
9
00:00:33,030 --> 00:00:33,600
OK.
10
00:00:33,870 --> 00:00:40,560
So let's start with this real quick and using routes from the beginning of this course.
11
00:00:40,590 --> 00:00:44,690
We could however use a controller and display the information on The View.
12
00:00:44,720 --> 00:00:45,410
OK.
13
00:00:45,900 --> 00:00:50,970
I'm using routes because it's a lot easier to show you this information here now and then later on that
14
00:00:50,970 --> 00:00:52,900
will apply to a project.
15
00:00:52,900 --> 00:00:53,650
All right.
16
00:00:54,060 --> 00:00:58,210
So what is a model.
17
00:00:58,270 --> 00:01:04,290
In our bill how do we control the model how do we access the information from the model how we actually
18
00:01:04,290 --> 00:01:05,780
use it right.
19
00:01:05,910 --> 00:01:07,520
How can we what is a model right.
20
00:01:07,550 --> 00:01:11,540
Well I already explained to you that the model is a class that deals with databases.
21
00:01:11,540 --> 00:01:16,080
Right but that doesn't help much right to understand exactly what a model is right.
22
00:01:16,080 --> 00:01:17,360
Let me show you.
23
00:01:17,370 --> 00:01:22,950
So let's go to a terminal real quick and let's create one in order for us to access information from
24
00:01:22,950 --> 00:01:29,490
the database using eloquent which is that that functionality or Clarabell that deals with the queries
25
00:01:29,640 --> 00:01:35,820
in a very easy format in order for me to access that all those functions that we have to create a model
26
00:01:35,940 --> 00:01:37,190
that's a class.
27
00:01:37,350 --> 00:01:41,800
So BHB when I use this command write a command tool areason.
28
00:01:42,030 --> 00:01:48,850
So BHB artisan make call and model and now we give it a name.
29
00:01:48,870 --> 00:01:51,720
I'm going to create a model called post.
30
00:01:51,730 --> 00:01:52,660
So ACAP it all.
31
00:01:52,680 --> 00:01:56,170
That's a first lady who will be in an uppercase right post.
32
00:01:56,370 --> 00:01:56,970
Right.
33
00:01:57,000 --> 00:02:04,030
And then if I flagged this like this with a name it would create a migration.
34
00:02:04,050 --> 00:02:04,990
All right Alisyn.
35
00:02:05,090 --> 00:02:05,830
Time.
36
00:02:05,910 --> 00:02:09,910
Remember when we started creating migrations so that way we can define our tables.
37
00:02:10,200 --> 00:02:12,350
Well if I do this it would create a migration.
38
00:02:12,360 --> 00:02:14,700
If I do it without it it would create a model.
39
00:02:14,700 --> 00:02:18,170
So let's do it without a first let's click enter.
40
00:02:18,420 --> 00:02:19,790
So nice created.
41
00:02:19,800 --> 00:02:26,760
Now remember that toys or models were going to be right here in the same root as app.
42
00:02:27,210 --> 00:02:27,680
Right.
43
00:02:27,690 --> 00:02:34,110
So you know one second I'll show you right now not the same route not the same level as her app but
44
00:02:34,140 --> 00:02:36,870
inside app and models should be right here.
45
00:02:36,870 --> 00:02:43,290
Now I have to synchronize my app folder because there we go.
46
00:02:43,680 --> 00:02:45,630
So now is available here if I double click it.
47
00:02:45,630 --> 00:02:50,190
Now you could see that he just creates this file name post.
48
00:02:50,190 --> 00:02:51,250
We are importing.
49
00:02:51,270 --> 00:02:53,290
We have this name name space.
50
00:02:53,320 --> 00:02:57,650
She has me call app so we can access this from somewhere else.
51
00:02:57,690 --> 00:03:00,270
We can use use somewhere else.
52
00:03:00,360 --> 00:03:06,060
So we are importing the model and we of course that's how we are extending it here.
53
00:03:06,070 --> 00:03:10,030
Right we are standing post from here.
54
00:03:10,200 --> 00:03:10,870
Right.
55
00:03:11,250 --> 00:03:17,490
So if you click if you have I think it will it works like this on Windows if you have windows or you
56
00:03:17,490 --> 00:03:24,510
click control click if you use an HP storm you can see why the model class does.
57
00:03:24,510 --> 00:03:32,020
I can see all the stuff the has all the properties that we can play around with.
58
00:03:32,040 --> 00:03:33,370
All right.
59
00:03:34,200 --> 00:03:38,000
And it's has a bunch of methods here.
60
00:03:38,010 --> 00:03:38,740
All right.
61
00:03:38,970 --> 00:03:41,350
Let's go back to post.
62
00:03:41,500 --> 00:03:47,940
So so now that we have this post class this model we can access it.
63
00:03:47,940 --> 00:03:50,080
We can now play around with eloquent.
64
00:03:50,130 --> 00:03:51,040
Right.
65
00:03:51,060 --> 00:03:52,230
All right use me.
66
00:03:52,770 --> 00:03:59,460
So one of the first things that you've got to understand here is that by default when we create a migration
67
00:04:00,140 --> 00:04:03,190
is called the name of the model.
68
00:04:03,240 --> 00:04:06,200
Is has the same name on the model in all lowercase.
69
00:04:06,210 --> 00:04:08,900
So we created this post.
70
00:04:08,910 --> 00:04:11,330
This model by itself right now.
71
00:04:11,380 --> 00:04:12,280
All right.
72
00:04:12,330 --> 00:04:13,060
We didn't create it.
73
00:04:13,070 --> 00:04:14,670
Migration what are we going to do then a minute.
74
00:04:14,670 --> 00:04:23,340
Right now this this model here things that a table name that we have in our database is called polls
75
00:04:23,400 --> 00:04:29,190
like this because it converts this into all lowercase and then plural all the time.
76
00:04:29,190 --> 00:04:34,210
So if we had an article this was already gone that table would be articles.
77
00:04:34,230 --> 00:04:35,930
So now we have access.
78
00:04:35,940 --> 00:04:39,620
I know you don't understand it right now but I want you to keep an open mind.
79
00:04:39,630 --> 00:04:47,070
We have access to all tables to a stable from this class is thinking we have a pool stable in the age
80
00:04:47,070 --> 00:04:47,420
right.
81
00:04:47,430 --> 00:04:49,090
We do have one.
82
00:04:49,110 --> 00:04:49,870
All right.
83
00:04:50,340 --> 00:04:55,830
So it just in case in the future you had this model named differently like you and I don't know why
84
00:04:55,830 --> 00:05:00,890
would you do that but just in case your model was named post.
85
00:05:01,320 --> 00:05:01,820
I don't know.
86
00:05:01,830 --> 00:05:03,620
Admiral or something like that.
87
00:05:03,870 --> 00:05:12,690
Then you have to come here and tell Clarabell to know that the table is not Polsce admins because it's
88
00:05:12,680 --> 00:05:13,950
going I think you have a table like this.
89
00:05:13,960 --> 00:05:15,940
Adman's right.
90
00:05:16,050 --> 00:05:25,210
So you're going to have to come here and ryot protect the property within with a variable table and
91
00:05:25,220 --> 00:05:32,560
just define it right here and you say listen Lavell I might say it was not named post adman's but his
92
00:05:32,560 --> 00:05:33,790
name posts.
93
00:05:33,800 --> 00:05:40,820
So now you're able to use this class to do all the methods and properties and then access all the stuff
94
00:05:41,030 --> 00:05:41,690
from eloquent.
95
00:05:41,690 --> 00:05:42,590
Right.
96
00:05:43,120 --> 00:05:43,470
All right.
97
00:05:43,490 --> 00:05:51,830
So now another thing that you also have to know is that by default this model here things that your
98
00:05:51,830 --> 00:05:54,830
table has a column name ID.
99
00:05:54,960 --> 00:05:57,070
All right like this.
100
00:05:57,080 --> 00:06:05,650
So he has a cold primary primary key name ID by default.
101
00:06:06,190 --> 00:06:06,790
OK.
102
00:06:07,000 --> 00:06:09,330
So you can access that and you're going to see that later on.
103
00:06:09,350 --> 00:06:17,840
But if for some reason your column name your primary key is not name ID is name something like post
104
00:06:17,840 --> 00:06:21,890
Id make sure that you come here and you write it down.
105
00:06:21,880 --> 00:06:28,370
Here you define it so that when we you are using eloquent Danos that your primary keys name different
106
00:06:28,490 --> 00:06:33,510
than the default one which is this which you really don't have to write it down.
107
00:06:33,620 --> 00:06:34,380
OK.
108
00:06:34,850 --> 00:06:38,720
It just takes a has those columns name like that.
109
00:06:38,720 --> 00:06:40,770
I was just letting you know that that's how you do it.
110
00:06:40,790 --> 00:06:45,770
If you have a totally different name for your table or for your ID.
111
00:06:46,280 --> 00:06:47,420
OK.
112
00:06:48,050 --> 00:06:51,220
So anyway let's get to this.
113
00:06:51,230 --> 00:06:59,930
I'm going to comment this out and I'm going to use the poles model right there so I know that you didn't
114
00:06:59,960 --> 00:07:01,190
understand much in this lecture.
115
00:07:01,190 --> 00:07:04,970
But the world is going to become very clearly clear later on.
116
00:07:04,970 --> 00:07:08,870
So now let's go back to routes.
117
00:07:08,870 --> 00:07:15,470
All right so let's go to HDTV and then routes and here we're going to make a comment so I'm going to
118
00:07:15,620 --> 00:07:21,740
take some comment block from here and I'm pasting here.
119
00:07:21,760 --> 00:07:24,830
I'm going to call this eloquent
120
00:07:27,200 --> 00:07:30,760
or of the relational model right.
121
00:07:31,190 --> 00:07:34,790
That's the name all for our AM.
122
00:07:34,880 --> 00:07:35,970
All right.
123
00:07:36,620 --> 00:07:39,470
Choose me.
124
00:07:39,470 --> 00:07:41,990
All right so let's create a route.
125
00:07:41,990 --> 00:07:45,160
Real quick.
126
00:07:45,160 --> 00:07:46,570
All right.
127
00:07:46,850 --> 00:07:52,070
This is going to make a lot more sense once we get into the application later on the course.
128
00:07:52,070 --> 00:07:56,160
So we're going to we're going to read some information already.
129
00:07:56,180 --> 00:08:03,770
We already have this comment that we can or we can actually name it find and we're going to have a closure
130
00:08:03,760 --> 00:08:04,400
function.
131
00:08:04,420 --> 00:08:09,530
And like I said we can use this in a control if we wanted to I'm just want to use it like this now and
132
00:08:09,530 --> 00:08:15,940
then later on when we build application we use it and we use the controllers in our application.
133
00:08:16,490 --> 00:08:20,370
We're using router right now to show you everything how everything works.
134
00:08:20,380 --> 00:08:30,260
So let's say for example that I want to access information I want to retrieve information from the database
135
00:08:30,590 --> 00:08:31,640
using eloquence.
136
00:08:31,700 --> 00:08:32,680
How do we do it.
137
00:08:32,780 --> 00:08:33,760
Let me show you.
138
00:08:34,150 --> 00:08:44,050
So now I'm going to go like this pose create a variable and I'm going to do this app and you see the
139
00:08:44,480 --> 00:08:51,370
this is backslash not a forward slash like this backslash like in the Windows machine.
140
00:08:51,380 --> 00:08:56,430
And then I would name I would go and refer to that post.
141
00:08:56,920 --> 00:08:58,430
You see that.
142
00:08:58,460 --> 00:09:01,370
So what I'm doing here is referring to this namespace.
143
00:09:01,370 --> 00:09:04,070
Remember that everything's right here on their app.
144
00:09:04,340 --> 00:09:13,430
And then the class is right here so I'm referring to that there but I know I can do that.
145
00:09:13,490 --> 00:09:14,620
I don't have to do that here.
146
00:09:14,620 --> 00:09:21,260
I can go ahead and take that off and go all the way to my application on top here and do this use in
147
00:09:21,280 --> 00:09:22,310
place there.
148
00:09:22,420 --> 00:09:29,310
And now I'm importing this class this functionality this post class right here this model.
149
00:09:29,620 --> 00:09:35,660
Now you don't see it but we have a lot of methods and properties available to us from this because we
150
00:09:35,650 --> 00:09:36,650
are extending the model.
151
00:09:36,640 --> 00:09:38,340
Remember this is a parent.
152
00:09:38,650 --> 00:09:43,300
So automatically Polsce is going to have all these methods like safe they destroy.
153
00:09:43,300 --> 00:09:47,410
I mean a whole bunch of different methods that there are there are so many of them that I don't even
154
00:09:47,410 --> 00:09:48,300
know them by heart.
155
00:09:48,380 --> 00:09:49,190
OK.
156
00:09:49,180 --> 00:09:54,060
So you'll learn this you know I asked you to go along in the course of course.
157
00:09:54,320 --> 00:09:55,140
So posts.
158
00:09:55,250 --> 00:09:56,250
So how do we find it.
159
00:09:56,270 --> 00:10:02,830
Well we say post we write the name and because this is going to be a static method that would put our
160
00:10:02,840 --> 00:10:06,560
call in and we say all that.
161
00:10:06,800 --> 00:10:16,630
Now this is pulling all the records right and saving it right here on this pulse variable.
162
00:10:17,270 --> 00:10:18,760
So now if we want to see it.
163
00:10:18,910 --> 00:10:21,940
So percentile for each.
164
00:10:21,940 --> 00:10:22,670
We look through it
165
00:10:25,830 --> 00:10:27,650
right.
166
00:10:29,000 --> 00:10:30,050
As opposed
167
00:10:34,120 --> 00:10:35,440
to how we go.
168
00:10:35,440 --> 00:10:38,210
Let's return that and see that in the browser.
169
00:10:39,320 --> 00:10:41,530
Actually this is called fine.
170
00:10:41,790 --> 00:10:44,480
I'm just going to name or rename it to read.
171
00:10:44,480 --> 00:10:45,330
All right.
172
00:10:46,000 --> 00:10:50,500
So let's go here and see what we can do.
173
00:10:50,600 --> 00:10:52,000
Read Antar.
174
00:10:52,490 --> 00:10:53,890
OK.
175
00:10:54,670 --> 00:10:59,670
Oh you know why we don't have a record in our database so that's why we don't see anything less just
176
00:10:59,680 --> 00:11:10,580
inserted because I think that one of the last lecture was to be HP is this alarm bill so I'm inserting
177
00:11:10,580 --> 00:11:14,660
some Recker that where we have some information.
178
00:11:15,130 --> 00:11:16,130
OK.
179
00:11:16,340 --> 00:11:23,670
You should be doing the same thing and you're going to a certain time stamp or whatever.
180
00:11:23,940 --> 00:11:25,190
Hopefully give me an error.
181
00:11:25,180 --> 00:11:26,100
There we go.
182
00:11:26,570 --> 00:11:28,790
Now we go and check it out real quick.
183
00:11:28,790 --> 00:11:29,740
See a mess.
184
00:11:29,780 --> 00:11:32,070
Read Antar.
185
00:11:32,270 --> 00:11:36,020
As you can see we are echoing the title.
186
00:11:36,180 --> 00:11:38,280
All right.
187
00:11:38,300 --> 00:11:39,570
Beautiful.
188
00:11:40,250 --> 00:11:42,450
So now you can also.
189
00:11:43,000 --> 00:11:44,060
All right.
190
00:11:44,680 --> 00:11:46,010
We can also find the record.
191
00:11:46,000 --> 00:11:48,400
So now we know that we have a record there less.
192
00:11:48,400 --> 00:11:55,320
Take a look to see was the ideal of it right.
193
00:11:56,140 --> 00:11:59,100
We have a record I did on number two.
194
00:11:59,110 --> 00:12:00,250
Cool.
195
00:12:00,430 --> 00:12:01,070
All right.
196
00:12:01,390 --> 00:12:04,190
So let me show you.
197
00:12:04,180 --> 00:12:06,340
So now let's just comment all this out.
198
00:12:06,380 --> 00:12:09,860
And for time's sake I'm going to paste it right guys.
199
00:12:09,880 --> 00:12:10,340
Don't do it.
200
00:12:10,340 --> 00:12:19,040
I want you to write it down but I'm going to get at it from round and say find and come here.
201
00:12:19,040 --> 00:12:23,350
And then I say pause find one.
202
00:12:23,350 --> 00:12:24,100
All right.
203
00:12:24,430 --> 00:12:29,640
And if we go here come back here we say find an author.
204
00:12:29,770 --> 00:12:31,870
We'll pass on.
205
00:12:32,210 --> 00:12:36,230
Oh you know what we would have to look through because it's finding one post.
206
00:12:36,230 --> 00:12:39,890
So with this comment is out and let's just return it
207
00:12:42,640 --> 00:12:46,720
fool's title and just take the s out of it.
208
00:12:47,050 --> 00:12:49,690
OK let's come back here.
209
00:12:49,880 --> 00:12:52,360
Antar Whoops.
210
00:12:52,370 --> 00:12:54,980
All right we have a narrow there we don't forgot the semi-colon
211
00:13:02,060 --> 00:13:04,410
polls find.
212
00:13:04,580 --> 00:13:07,760
Let's do it.
213
00:13:10,280 --> 00:13:10,740
OK.
214
00:13:10,850 --> 00:13:11,390
Get.
215
00:13:11,410 --> 00:13:12,490
There we go.
216
00:13:12,500 --> 00:13:16,210
That should bring out the No.
217
00:13:16,250 --> 00:13:17,900
Oh you know why he's not returning.
218
00:13:17,890 --> 00:13:19,140
Sorry about that guys.
219
00:13:19,170 --> 00:13:23,280
We're now looking for the number one we're looking for the number two.
220
00:13:23,300 --> 00:13:23,920
All right.
221
00:13:23,990 --> 00:13:25,510
Cool Antar.
222
00:13:25,610 --> 00:13:26,510
There we go.
223
00:13:26,540 --> 00:13:32,690
Now we find on the record that the number two when we bring out the title and remember this is coming
224
00:13:32,750 --> 00:13:34,920
like an object now.
225
00:13:34,930 --> 00:13:41,340
All right so we're pulling out all that if we have multiple ones then we will get in find.
226
00:13:41,330 --> 00:13:45,340
All right we will pull everything from here.
227
00:13:45,350 --> 00:13:45,700
All right.
228
00:13:45,710 --> 00:13:50,050
But you were the one finding the record ID number two.
229
00:13:50,120 --> 00:13:51,390
Beautiful right.
230
00:13:51,400 --> 00:13:56,180
Anyway thank you so much for watching this lecture I hope you're liking how to use eloquent how easy
231
00:13:56,170 --> 00:13:57,190
it is right.
232
00:13:57,530 --> 00:14:04,920
And remember that we can also use this anywhere we want as long as we import.
233
00:14:04,930 --> 00:14:05,320
All right.
234
00:14:05,330 --> 00:14:06,250
The motto.
235
00:14:06,530 --> 00:14:07,440
All right.
236
00:14:07,850 --> 00:14:13,910
So this fine med is available in the model in the pairing class.
237
00:14:13,930 --> 00:14:15,010
All right.
238
00:14:15,670 --> 00:14:19,050
In every way you imported You can use it just like I'm using it right now.
239
00:14:19,120 --> 00:14:24,110
Roadstar BHB thank you so much for watching this lecture and I'll see you in the next one.
240
00:14:24,110 --> 00:14:25,510
Take care.20209
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.