You are on page 1of 10

Update Data On DB

LAB 10
Muhammad Sufyian Mohd Azmi

Copyright by Muhammad Sufyian Mohd Azmi


Database Preparation

1. We use back the previous DB (firstproject) and previous table (students [“id,
”name”, “address”]).
2. So what we gonna do? We will produce a list with delete link on the list.
Then we will perform delete function on the link.

Copyright by Muhammad Sufyian Mohd Azmi


Create the link on view file

 Let’s create the link on view file (listDisplay.blade.php)


 Add the syntax below after delete link

URL name (must be the same as


on route)
Copyright by Muhammad Sufyian Mohd Azmi
Produce Route for function update

 Next is to produce function update at controller to perform update activity

Makesure this one is the same as we showStud function on controller to show


declared on update link (view file) original data

Copyright by Muhammad Sufyian Mohd Azmi


Show original data/value

1. Create function (showStudent) at controller (mbrControl.php) to display


original data

Model name

2. If we run the output, it will show raw data


URL look like this because on our
route, we set (‘upd/{id}’). And we
need to enter manually the id on
address bar.
Copyright by Muhammad Sufyian Mohd Azmi
Show original data/value

3. Next, we want to display original data on proper form


4. Create new file in views (updateData.blade.php)

Empty first

Hidden bcoz ID cannot be edited

Copyright by Muhammad Sufyian Mohd Azmi


Show original data/value
5. Modify showStud() function in controller

Variable that we use in form


(updateData.blade.php)

Form name (updateData.blade.php)

6. Test output by key in manually the ID on the url (example:


localhost:8000/upd/123)

Copyright by Muhammad Sufyian Mohd Azmi


Perform Update Function
7. Adjust action attribute in form that we created earlier (updateData.blade.php)

Must be similar name

8. Add new route to call function update to perform update data

Because we post
data from form

Copyright by Muhammad Sufyian Mohd Azmi


Create function update
9. Next is to create function update in controller to update data

Field name The name we


on DB declare on the
form

10. Run using URL (localhost::8000/senarai)….and you will get an error

Copyright by Muhammad Sufyian Mohd Azmi


 Error because, laravel need attribute timestamp, which we don’t have.
 So you need to modify a little bit
 Go to model and add

Copyright by Muhammad Sufyian Mohd Azmi

You might also like