Loading

Laravel

How to connect Database with Laravel?. The Complete Laravel Developer Course 2023 [Videos].

Laravel has made processing with database very easy. 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 simple student management system.

Connecting to Database

Configure the database in config/database.php file and create the college database with structure in MySQL as shown in the following table.

Database: College

Table: student

Column NameColumn DatatypeExtra
Idint(11)Primary key | Auto increment
Namevarchar(25)

We will see how to add, delete, update and retrieve records from database using Laravel in student table.

Sr.No.Record & Description
1Insert Records

We can insert the record using the DB facade with insert method.

2Retrieve Records

After configuring the database, we can retrieve the records using the DB facade with select method.

3Update Records

We can update the records using the DB facade with update method.

4Delete Records

We can delete the record using the DB facade with the delete method.

See All

Comments (491 Comments)

Submit Your Comment

See All Posts

Related Posts

Laravel / Blog

How to install Laravel ?

For managing dependencies, Laravel uses composer. Make sure you have a Composer installed on your system before you install Laravel. In this chapter, you will see the installation process of Laravel.
14-Feb-2022 /15 /491

Laravel / Blog

What is Laravel - Application Structure?

The application structure in Laravel is basically the structure of folders, sub-folders and files included in a project. Once we create a project in Laravel, we get an overview of the application structure as shown in the image here.
14-Feb-2022 /15 /491

Laravel / Blog

How to setup Configuration in Laravel?

n the previous chapter, we have seen that the basic configuration files of Laravel are included in the config directory. In this chapter, let us discuss the categories included in the configuration.
14-Feb-2022 /15 /491