Laravel Database
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
What is Laravel Database?
- A database is an organized collection of data.
- It is the collection of schemas, tables, queries, reports, views, and other objects.
- The data are typically organized to model aspects of reality in a way that supports processes requiring information, such as modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies.

laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Database Connecting to Database
- Laravel has made processing with database very simple. Laravel currently supports following 4 databases −
- MySQL
- Postgres
- SQLite
- SQL Server
- The query to the database can be fired using raw SQL, the fluent query builder, and the Eloquent ORM.
- To understand the all CRUD (Create, Read, Update, Delete) operations with Laravel, we will use easy student management system.
- Configure the database in config/database.php file and create the college database with structure in MySQL as shown in the following table.

Open a Connection to MySQL
- Before we can access data in the MySQL database, we need to be able to connect to the server:
Example
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
laravel , laravel framework , laravel documentation , laravel tutorial , laravel install , laracasts
Database − College
Table − student
Column Name | Data Type | Extra |
---|---|---|
Id | int(11) | Primary key | Auto increment |
Name | varchar(25) |
- Let’s see how to add, delete, update and retrieve records from database using Laravel in student table.
Column Name | Records | Description |
---|---|---|
1 | Insert Records | We can insert the record using the DB facade with insert method. |
2 | Retrieve Records | After configuring the database, we can retrieve the records using the DB facade with select method. |
3 | Update Records | We can update the records using the DB facade with update method. |
4 | Delete Records | We can delete the record using the DB facade with the delete method.. |
