Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
All right.
Welcome back my student.
So on this lecture here we are going to be learning about eloquent.
All right which is the functionality of Claribel there is actually one of the most popular ones because
it allows us to do a lot of database queries in a very easy easy format a lot easier than raw as well
.
OK so now how does it work.
This is the part where it gets most confusing in our and I want you to pay very close attention because
you need to get this.
OK.
So let's start with this real quick and using routes from the beginning of this course.
We could however use a controller and display the information on The View.
OK.
I'm using routes because it's a lot easier to show you this information here now and then later on that
will apply to a project.
All right.
So what is a model.
In our bill how do we control the model how do we access the information from the model how we actually
use it right.
How can we what is a model right.
Well I already explained to you that the model is a class that deals with databases.
Right but that doesn't help much right to understand exactly what a model is right.
Let me show you.
So let's go to a terminal real quick and let's create one in order for us to access information from
the database using eloquent which is that that functionality or Clarabell that deals with the queries
in a very easy format in order for me to access that all those functions that we have to create a model
that's a class.
So BHB when I use this command write a command tool areason.
So BHB artisan make call and model and now we give it a name.
I'm going to create a model called post.
So ACAP it all.
That's a first lady who will be in an uppercase right post.
Right.
And then if I flagged this like this with a name it would create a migration.
All right Alisyn.
Time.
Remember when we started creating migrations so that way we can define our tables.
Well if I do this it would create a migration.
If I do it without it it would create a model.
So let's do it without a first let's click enter.
So nice created.
Now remember that toys or models were going to be right here in the same root as app.
Right.
So you know one second I'll show you right now not the same route not the same level as her app but
inside app and models should be right here.
Now I have to synchronize my app folder because there we go.
So now is available here if I double click it.
Now you could see that he just creates this file name post.
We are importing.
We have this name name space.
She has me call app so we can access this from somewhere else.
We can use use somewhere else.
So we are importing the model and we of course that's how we are extending it here.
Right we are standing post from here.
Right.
So if you click if you have I think it will it works like this on Windows if you have windows or you
click control click if you use an HP storm you can see why the model class does.
I can see all the stuff the has all the properties that we can play around with.
All right.
And it's has a bunch of methods here.
All right.
Let's go back to post.
So so now that we have this post class this model we can access it.
We can now play around with eloquent.
Right.
All right use me.
So one of the first things that you've got to understand here is that by default when we create a migration
is called the name of the model.
Is has the same name on the model in all lowercase.
So we created this post.
This model by itself right now.
All right.
We didn't create it.
Migration what are we going to do then a minute.
Right now this this model here things that a table name that we have in our database is called polls
like this because it converts this into all lowercase and then plural all the time.
So if we had an article this was already gone that table would be articles.
So now we have access.
I know you don't understand it right now but I want you to keep an open mind.
We have access to all tables to a stable from this class is thinking we have a pool stable in the age
right.
We do have one.
All right.
So it just in case in the future you had this model named differently like you and I don't know why
would you do that but just in case your model was named post.
I don't know.
Admiral or something like that.
Then you have to come here and tell Clarabell to know that the table is not Polsce admins because it's
going I think you have a table like this.
Adman's right.
So you're going to have to come here and ryot protect the property within with a variable table and
just define it right here and you say listen Lavell I might say it was not named post adman's but his
name posts.
So now you're able to use this class to do all the methods and properties and then access all the stuff
from eloquent.
Right.
All right.
So now another thing that you also have to know is that by default this model here things that your
table has a column name ID.
All right like this.
So he has a cold primary primary key name ID by default.
OK.
So you can access that and you're going to see that later on.
But if for some reason your column name your primary key is not name ID is name something like post
Id make sure that you come here and you write it down.
Here you define it so that when we you are using eloquent Danos that your primary keys name different
than the default one which is this which you really don't have to write it down.
OK.
It just takes a has those columns name like that.
I was just letting you know that that's how you do it.
If you have a totally different name for your table or for your ID.
OK.
So anyway let's get to this.
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
understand much in this lecture.
But the world is going to become very clearly clear later on.
So now let's go back to routes.
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
take some comment block from here and I'm pasting here.
I'm going to call this eloquent
or of the relational model right.
That's the name all for our AM.
All right.
Choose me.
All right so let's create a route.
Real quick.
All right.
This is going to make a lot more sense once we get into the application later on the course.
So we're going to we're going to read some information already.
We already have this comment that we can or we can actually name it find and we're going to have a closure
function.
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
then later on when we build application we use it and we use the controllers in our application.
We're using router right now to show you everything how everything works.
So let's say for example that I want to access information I want to retrieve information from the database
using eloquence.
How do we do it.
Let me show you.
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
this is backslash not a forward slash like this backslash like in the Windows machine.
And then I would name I would go and refer to that post.
You see that.
So what I'm doing here is referring to this namespace.
Remember that everything's right here on their app.
And then the class is right here so I'm referring to that there but I know I can do that.
I don't have to do that here.
I can go ahead and take that off and go all the way to my application on top here and do this use in
place there.
And now I'm importing this class this functionality this post class right here this model.
Now you don't see it but we have a lot of methods and properties available to us from this because we
are extending the model.
Remember this is a parent.
So automatically Polsce is going to have all these methods like safe they destroy.
I mean a whole bunch of different methods that there are there are so many of them that I don't even
know them by heart.
OK.
So you'll learn this you know I asked you to go along in the course of course.
So posts.
So how do we find it.
Well we say post we write the name and because this is going to be a static method that would put our
call in and we say all that.
Now this is pulling all the records right and saving it right here on this pulse variable.
So now if we want to see it.
So percentile for each.
We look through it
right.
As opposed
to how we go.
Let's return that and see that in the browser.
Actually this is called fine.
I'm just going to name or rename it to read.
All right.
So let's go here and see what we can do.
Read Antar.
OK.
Oh you know why we don't have a record in our database so that's why we don't see anything less just
inserted because I think that one of the last lecture was to be HP is this alarm bill so I'm inserting
some Recker that where we have some information.
OK.
You should be doing the same thing and you're going to a certain time stamp or whatever.
Hopefully give me an error.
There we go.
Now we go and check it out real quick.
See a mess.
Read Antar.
As you can see we are echoing the title.
All right.
Beautiful.
So now you can also.
All right.
We can also find the record.
So now we know that we have a record there less.
Take a look to see was the ideal of it right.
We have a record I did on number two.
Cool.
All right.
So let me show you.
So now let's just comment all this out.
And for time's sake I'm going to paste it right guys.
Don't do it.
I want you to write it down but I'm going to get at it from round and say find and come here.
And then I say pause find one.
All right.
And if we go here come back here we say find an author.
We'll pass on.
Oh you know what we would have to look through because it's finding one post.
So with this comment is out and let's just return it
fool's title and just take the s out of it.
OK let's come back here.
Antar Whoops.
All right we have a narrow there we don't forgot the semi-colon
polls find.
Let's do it.
OK.
Get.
There we go.
That should bring out the No.
Oh you know why he's not returning.
Sorry about that guys.
We're now looking for the number one we're looking for the number two.
All right.
Cool Antar.
There we go.
Now we find on the record that the number two when we bring out the title and remember this is coming
like an object now.
All right so we're pulling out all that if we have multiple ones then we will get in find.
All right we will pull everything from here.
All right.
But you were the one finding the record ID number two.
Beautiful right.
Anyway thank you so much for watching this lecture I hope you're liking how to use eloquent how easy
it is right.
And remember that we can also use this anywhere we want as long as we import.
All right.
The motto.
All right.
So this fine med is available in the model in the pairing class.
All right.
In every way you imported You can use it just like I'm using it right now.
Roadstar BHB thank you so much for watching this lecture and I'll see you in the next one.
Take care.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.