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 Insert and Retrieve Data in Database – Laravel Framework

In this example, I am going to show you how to insert data in the database using laravel framework PHP.

First, creating table the SQL query:

CREATE TABLE student_details
(
id int NOT NULL AUTO_INCREMENT,
first_name varchar(50),
last_name varchar(50),
city_name varchar(50),
email varchar(50),
PRIMARY KEY (id)
);Code language: PHP (php)

Now, create three file for insert data in Laravel.

Step 1. Create a controller name as StudInsertController.php.
The file location is : (app/Http/Controllers/StudInsertController.php)

Step 2. Create view page name as stud_create.php
The file location is: (resources/views/stud_create.php)

Then put this code in your StudInsertController.php.

Then put this code in your stud_create.blade.php.

Step 3. Then go to routes as web.php and put this code.
The file location is : (routes/web.php)

Route::get('insert','StudInsertController@insertform');
Route::post('create','StudInsertController@insert');Code language: PHP (php)

Then, you can see the data is inserted.

PhpMyAdmin table with five inserted student rows: id, first_name, last_name, city_name and email

So, the data is inserted in the database, then we need to retrieve a record or data from the MySQL database.

Step 4. Create a controller for view name as StudViewController.php.
The file location is : (app/Http/Controllers/StudViewController.php)

Step 5. Create a view page name as stud_view.blade.php.
The file location is : (resources/views/stud_view.blade.php).

Then put this code StudViewController.php.

Then, retrieve the students data then put this code stud_view.blade.php.

Step 6. Then go to routes as web.php and put this code.
The file location is (routes/web.php)

Route::get('view-records','StudViewController@index');Code language: PHP (php)

Then, you can see the view page.

Laravel View Student Records page listing the five student rows retrieved from MySQL

Find Trusted Cardiac Hospitals

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

Explore Hospitals
MotoShare.in provides the perfect two-wheeler for every occasion—daily commuting, weekend escapes, tourist exploration, or test-riding your dream bike. Simplify your mobility with us!

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