To read data from the database, we use the below commands:-
1. DB::table(“Table_name“)->get() :- It returns all the data present in the given table of database. See below:-
2. DB::table(“table_name”)->where(“key1″,”key1_value”)->first() :- It returns all data of the row in which key value found. See below:-
3. DB::table(“table_name”)->pluck(“column_name”); :- It returns all the data stored in the given column from database.
Pluck :- pluck is a method in laravel which is used when we have to fetch a particular column from database.
4. DB::table(“Table_name”)->select(“column1”, “column2”, “column3”)->get() :- It is used to return the given data of the row. Means, if we call name and E-mail column then it returns the both with row-wise. See below how it works:-
5. DB::table(“Table_name”)->count() :- It returns the no. of rows. See below:-
There are 5 rows in my database so it returns 5.
6. DB::table(“Table_name”)->max(“ Column_name “) :- It returns the maximum id no. of your data from database. See below:-
See the Database Below:-
7. DB::table(“Table_name”)->min(“ Column_name “) :- It returns the minimum id no. of your data from database. See below:-
See the Database Below:-
8. DB::table(“Table_name”)->min(“Column_name”) :- It returns the average value of the given column.
Suppose I want the average value of the id column. See below:-
- What is On-Page Optimization and Off-page Optimization - March 14, 2024
- [SOLVED] Flutter : PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) - December 7, 2021
- [Solved] Flutter : Error: The getter ‘subhead’ isn’t defined for the class ‘TextTheme’ from package:flutter/src/material/text_theme.dart’ – searchable_dropdown - December 6, 2021