MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to Update and Delete data from database using Controller.

Update data from the database

To Update the data in database table we use update(). See the syntax below:-

Laravel update syntax: DB::table with where on id, then update with key-value pairs

See the below code for updating data in the database. I’m updating my id=2 name and email.

Laravel controller code updating name and email for id 2 in the tinker table with update()

When we run the page, it will update the id=2 data from the above data, if the page returns 1 then data updated else not updated. Let’s see the database.

PhpMyAdmin table showing row id 2 updated to Rahul Kumar with rahulkumar@gmail.com

See the above image, the data of id 2 is updated.

Note:- If we can’t add where condition, then it will update all names and emails.

Delete data from the database

We use delete() to delete the data from the database. See the syntax below:-

Laravel delete syntax: DB::table(Table_name)->where(id, id_no.)->delete();

I’m deleting id=2 from my database, see the code below:-

Laravel controller code deleting id 2 from the tinker table with DB::table()->where()->delete()

See the output below when we run the page.

PhpMyAdmin tables before and after running delete code, with the id 2 row removed

Note:- If we can’t add where condition, then it will Delete all rows.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

Python Tutorials: Database operations using python – mysql

This tutorial connects Python to MySQL with the official mysql-connector-python driver and runs the full set of CRUD operations: create a database and table, then insert, read,…

Read More

Elastic Tutorial: Elasticsearch 8.X Installation & CRUD in Linux

Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have…

Read More

Python Tutorials: Files Operations

Python File Operations Python – Working with files Python File Operations: Modes Python File Operations: Writing a file Python File Operations: CRUD Rajesh Kumar I’m Rajesh Kumar,…

Read More

AJAX Crud with laravel 5.8

sam MotoShare.in is your go-to platform for adventure and exploration. Rent premium bikes for epic journeys or simple scooters for your daily errands—all with the MotoShare.in advantage…

Read More

Elasticsearch Lab#1 – CRUD

Reference Sample Data & Query – https://github.com/devopsschool-demo-labs-projects/elasticsearch Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world…

Read More

CRUD USING API IN Flutter (Part 1)

INTRODUCTION: In general, the use of JSON is used to communicate data from client to server and from server to client. In this article we are going…

Read More