Professional Documents
Culture Documents
LAB 7
Muhammad Sufyian Mohd Azmi
Open MySQL and create DB “firstproject” and next create simple table
name it as “users” with 3 attributes (“id”,”name”,”age”) and lastly insert any
data/value into the table.
But what if we do not want our table and model name using Plurals and
Singular, perhaps we want to use Malay word which do not have concept
Plurals or Singular?
Then we have to tell Laravel manually which table we want to use in a project
(step is done in Model File). Refer last slide
Copyright by Muhammad Sufyian Mohd Azmi
Fetch Data Using Model and Display
Using View File
1. Lets use back the previous DB (refer slide 2).
2. Create a table “customers” in MySQL
3. Create Model file using concept Plurals Singular. So based on the table
name that we created which is customers, so our model name should be
Customer.
4. Syntax to create Model is php artisan make:model <model_name>
Don’t forget ;
Lets fetch the data and try to display. Create any function to return data in controller
Model’s name
Fetch Data Using Model and Display
Using View File
7. Create Route for controller
Controller name
We do not want the data look like that, we want to display in proper look (in view
[html] file).