How To Use DB Queries In Laravel

How To Use DB Queries In Laravel - Laravel is PHP Framework for Web Application. It is a Free -> Open Source PHP Framework. It's follow the Standard Coding way MVC (Models, Views, Controllers) Concept.
Model -> It mainly interact with the Database. Database Queries like Insert,Update,Select,Delete etc.
Controller -> It's responsible for Users Action and Buisness Logic of the application.
View -> It's most interacting part of the web application for Users.
Now DB Queries - How to use in Laravel code
1.Check the columns in the database table for particular table query is --
$columns = DB::select( DB::raw('SHOW COLUMNS FROM TABLE_NAME'));
2. If you want to modify your database table
DB::statement('ALTER TABLE TABLE_NAME MODIFY COLUMN_NAME DATATYPE NOT NULL');
DB::statement('ALTER TABLE User MODIFY user_id INT(20) NOT NULL');
3. Get data for particular table form database
DB::select('SELECT * FROM TABLE_NAME');
with where condition DB::select('SELECT * FROM TABLE_NAME WHERE COLUMN_NAME = "Value" ');
Note: Use DB Class on the top of your class in Laravel

Comments

Popular posts from this blog

Prestashop Create Admin Controller inside Admin Folder

Prestashop Pass Controller Variables To TPL

Prestashop Admin Controller get Access Denied Error