๐Ÿ“š

Model

model are used to define the tables of the db interm of classes so that we have more controll over the database functionality
we can
  1. change the table name
  1. combine the tables
  1. write logic and mathematical functions
  1. define database structure also
 
Model name will always be singular
๐Ÿ”ฅ
suppose you are having a table named โ€œemployeesโ€ so the model will be โ€œemployeeโ€
notion image
๐Ÿ”ฅ
Now if you are having your table name as emp then can you map that in your model ? The answer is YES you have to add a line in your model and you are good to go

Requirement

when you are using the model then you need a controller also that will help to deal with routes and connection between routes and model.
to make model
now as we have discussed if you are a table called โ€œusersโ€ then the User model will automatically map your model to the table
to make controller
UserController โ†’
notion image
๐Ÿ”ฅ
::all() is a method of model to fetch all the data
Configure controller on route โ†’ to see the result of model in your pc
 

Diffrent table name with diffrent name of model

suppose you are having a table that is completely diffrent name and then also you want to fetch the data of that table so you have to go to your model and add a line of code under class
 

To save data

first make a controller and a model
take the controllerโ€™s page as post route and call the model
Inside model โ†’
notion image
you have to redirect also after save() operationโ€ฆ
 

To update

make a route for โ€œeditโ€ route with id โ†’ for get request
without id for post request
notion image