SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Object-Oriented
Programming
(with Laravel)
By: Shahrzad Peyman
Session 5
May-2017
shahrzad.peymaan@gmail.com
1
2
Today’s Presentation
• DataBase
• Configuration
• Multiple Connection
• Raw Queries
• Query Builder
• Pagination
3
DataBase
Laravel makes interacting with databases extremely simple
across a variety of database backends using either raw SQL,
the fluent query builder, and the Eloquent ORM. Currently,
Laravel supports four databases:
• MySQL
• Postgres
• SQLite
• SQL Server
Configuration
4
The database configuration for your application is located
at config/database.php.
In this file you may define all of your database
connections, as well as specify which connection should
be used by default.
Examples for most of the supported database systems
are provided in this file.
Using Multiple DataBase
Connection
5
When using multiple connections, you may
access each connection via the connection
method on th DB facade. The name passed to
the connection method should correspond to
one of the connections listed in your config/
database.php configuration file:
6
Running Raw SQL Queries
Once you have configured your database
connection, you may run queries using the DB
facade.
The DB facade provides methods for each type of
query: select, update, insert, delete, and
statement.
Running a Select Query
7
8
Running a Select Query
The first argument passed to the select method is
the raw SQL query, while the second argument is
any parameter bindings that need to be bound to
the query. Typically, these are the values of the
where clause constraints. The select method will
always return an array of results.
Running Insert/Update/Delete
Statements
9
Running a General
Statement
10
Some database statements do not return any
value. For these types of operations, you may
use the statement method on the DB facade:
DataBase Transactions
You may use the transaction method on the DB facade to
run a set of operations within a database transaction. If an
exception is thrown within the transaction Closure, the
transaction will automatically be rolled back. If the Closure
executes successfully, the transaction will automatically be
committed. You don't need to worry about manually rolling
back or committing while using the transaction method:
Manually Using Transaction
Query Builder
Laravel's database query builder provides a
convenient, fluent interface to creating and running
database queries.
It can be used to perform most database operations in
your application and works on all supported database
systems.
Retrieving All Rows From A Table
14
15
The get method returns an IlluminateSupportCollection
containing the results where each result is an instance
of the PHP StdClass object. You may access each
column's value by accessing the column as a property of
the object:
Retrieving All Rows From A Table
Retrieving A Single Row / Column From
A Table
16
Retrieving A List Of Column Values
17
Aggregates
18
The query builder also provides a variety of aggregate
methods such as count, max, min, avg, and sum. You may
call any of these methods after constructing your query:
19
Selects
20
Raw Expressions
Sometimes you may need to use a raw expression in a
query. These expressions will be injected into the
query as strings, so be careful not to create any SQL
injection points! To create a raw expression, you may
use the DB:raw method:
21
Inner Join
The query builder may also be used to write join statements.
To perform a basic "inner join", you may use the join
method on a query builder instance. The first argument
passed to the join method is the name of the table you need
to join to, while the remaining arguments specify the column
constraints for the join. Of course, as you can see, you can
join to multiple tables in a single query:
22
Left Join
If you would like to perform a "left join" instead of an
"inner join", use the leftJoin method. The leftJoin
method has the same signature as the join method:
Cross Join
23
To perform a "cross join" use the crossJoin method
with the name of the table you wish to cross join to.
Cross joins generate a cartesian product between
the first table and the joined table:
24
Advanced Join
24
25
Unions
The query builder also provides a quick way to
"union" two queries together. For example, you
may create an initial query and use the union
method to union it with a second query:
25
26
Where Clauses
You may use the where method
on a query builder instance to
add where clauses to the query.
The most basic call to where
requires three arguments. The
first argument is the name of the
column. The second argument is
an operator, which can be any of
the database's supported
operators. Finally, the third
argument is the value to
evaluate against the column.
27
Or Statements
28
Additional Where Clauses
29
Additional Where Clauses
30
Additional Where Clauses
31
Parameters Grouping
Sometimes you may need to create more advanced where
clauses such as "where exists" clauses or nested
parameter groupings. The Laravel query builder can handle
these as well. To get started, let's look at an example of
grouping constraints within parenthesis
32
Ordering, Grouping, Limit, & Offset
Ordering, Grouping, Limit, & Offset
33
Ordering, Grouping, Limit, & Offset
34
35
Conditional Clauses
Sometimes you may want clauses to apply to a query only
when something else is true. For instance you may only
want to apply a where statement if a given input value is
present on the incoming request. You may accomplish this
using the when method:
36
Conditional Clauses
37
Inserts
38
Updates/Deletes
39
Increment/Decrement
40
Pagination
In other frameworks, pagination can be very painful. Laravel's
paginator is integrated with the query builder and Eloquent ORM
and provides convenient, easy-to-use pagination of database
results out of the box. The HTML generated by the paginator is
compatible with the Bootstrap CSS framework.
There are several ways to paginate items. The simplest is by
using the paginate method on the query builder or an Eloquent
query. The paginate method automatically takes care of setting
the proper limit and offset based on the current page being
viewed by the user. By default, the current page is detected by
the value of the page query string argument on the HTTP request.
Of course, this value is automatically detected by Laravel, and is
also automatically inserted into links generated by the paginator.
41
Pagination/Simple Pagination
42
Displaying Pagination Results
43
Customize the Pagination View
By default, the views rendered to display the
pagination links are compatible with the
Bootstrap CSS framework. However, if you are
not using Bootstrap, you are free to define your
own views to render these links. When calling
the link method on a paginator instance, pass
the view name as the first argument to the
method:
44
Paginator Instance Methods
Object Oriented Programming with Laravel - Session 5

Weitere ähnliche Inhalte

Was ist angesagt?

Manindra kishore _incident_handling_n_log_analysis - ClubHack2009
Manindra kishore _incident_handling_n_log_analysis - ClubHack2009Manindra kishore _incident_handling_n_log_analysis - ClubHack2009
Manindra kishore _incident_handling_n_log_analysis - ClubHack2009
ClubHack
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
Pranav Sharma
 

Was ist angesagt? (19)

SQL Injection Attacks
SQL Injection AttacksSQL Injection Attacks
SQL Injection Attacks
 
SQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
SQL Injection Attack Detection and Prevention Techniques to Secure Web-SiteSQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
SQL Injection Attack Detection and Prevention Techniques to Secure Web-Site
 
Defending against Injections
Defending against InjectionsDefending against Injections
Defending against Injections
 
Oracle Concurrent Program Setup document
Oracle Concurrent Program Setup  documentOracle Concurrent Program Setup  document
Oracle Concurrent Program Setup document
 
Asp.Net Database
Asp.Net DatabaseAsp.Net Database
Asp.Net Database
 
Web application penetration using SQLMAP.
Web application penetration using SQLMAP.Web application penetration using SQLMAP.
Web application penetration using SQLMAP.
 
D:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql InjectionD:\Technical\Ppt\Sql Injection
D:\Technical\Ppt\Sql Injection
 
Sqlmap
SqlmapSqlmap
Sqlmap
 
Sql Injection Attacks Siddhesh
Sql Injection Attacks SiddheshSql Injection Attacks Siddhesh
Sql Injection Attacks Siddhesh
 
Manindra kishore _incident_handling_n_log_analysis - ClubHack2009
Manindra kishore _incident_handling_n_log_analysis - ClubHack2009Manindra kishore _incident_handling_n_log_analysis - ClubHack2009
Manindra kishore _incident_handling_n_log_analysis - ClubHack2009
 
Sql injection
Sql injectionSql injection
Sql injection
 
SQL Injection
SQL Injection SQL Injection
SQL Injection
 
SQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint PresentationSQL Injections - A Powerpoint Presentation
SQL Injections - A Powerpoint Presentation
 
Asp.Net The Data List Control
Asp.Net   The Data List ControlAsp.Net   The Data List Control
Asp.Net The Data List Control
 
Koha Cataloguing Module
Koha Cataloguing ModuleKoha Cataloguing Module
Koha Cataloguing Module
 
Instant DBMS Homework Help
Instant DBMS Homework HelpInstant DBMS Homework Help
Instant DBMS Homework Help
 
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
 
Rail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendranRail3 intro 29th_sep_surendran
Rail3 intro 29th_sep_surendran
 

Ähnlich wie Object Oriented Programming with Laravel - Session 5

Object Oriented Programming with Laravel - Session 3
Object Oriented Programming with Laravel - Session 3Object Oriented Programming with Laravel - Session 3
Object Oriented Programming with Laravel - Session 3
Shahrzad Peyman
 

Ähnlich wie Object Oriented Programming with Laravel - Session 5 (20)

Object Oriented Programming with Laravel - Session 3
Object Oriented Programming with Laravel - Session 3Object Oriented Programming with Laravel - Session 3
Object Oriented Programming with Laravel - Session 3
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
SCWCD : The servlet model : CHAP : 2
SCWCD  : The servlet model : CHAP : 2SCWCD  : The servlet model : CHAP : 2
SCWCD : The servlet model : CHAP : 2
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
 
Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5Migrating from PHP 4 to PHP 5
Migrating from PHP 4 to PHP 5
 
SCWCD : Handling exceptions : CHAP : 5
SCWCD : Handling exceptions : CHAP : 5SCWCD : Handling exceptions : CHAP : 5
SCWCD : Handling exceptions : CHAP : 5
 
SCWCD : The servlet model CHAP : 2
SCWCD : The servlet model CHAP : 2SCWCD : The servlet model CHAP : 2
SCWCD : The servlet model CHAP : 2
 
Php and MySQL Web Development
Php and MySQL Web DevelopmentPhp and MySQL Web Development
Php and MySQL Web Development
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
WEB-MODULE 4.pdf
WEB-MODULE 4.pdfWEB-MODULE 4.pdf
WEB-MODULE 4.pdf
 
How to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon RedshiftHow to Fine-Tune Performance Using Amazon Redshift
How to Fine-Tune Performance Using Amazon Redshift
 
Database novelty detection
Database novelty detectionDatabase novelty detection
Database novelty detection
 
Ebook7
Ebook7Ebook7
Ebook7
 
Sql interview question part 7
Sql interview question part 7Sql interview question part 7
Sql interview question part 7
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER:  Programming sql server data miningMS SQL SERVER:  Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
 

Mehr von Shahrzad Peyman (9)

Web Design & Development - Session 9
Web Design & Development - Session 9Web Design & Development - Session 9
Web Design & Development - Session 9
 
Web Design & Development - Session 8
Web Design & Development - Session 8Web Design & Development - Session 8
Web Design & Development - Session 8
 
Web Design & Development - Session 7
Web Design & Development - Session 7Web Design & Development - Session 7
Web Design & Development - Session 7
 
Web Design & Development - Session 6
Web Design & Development - Session 6Web Design & Development - Session 6
Web Design & Development - Session 6
 
Web Design & Development - Session 4
Web Design & Development - Session 4Web Design & Development - Session 4
Web Design & Development - Session 4
 
Web Design & Development - Session 3
Web Design & Development - Session 3Web Design & Development - Session 3
Web Design & Development - Session 3
 
Web Design & Development - Session 2
Web Design & Development - Session 2Web Design & Development - Session 2
Web Design & Development - Session 2
 
Web Design & Development - Session 1
Web Design & Development - Session 1Web Design & Development - Session 1
Web Design & Development - Session 1
 
Object Oriented Programming with Laravel - Session 1
Object Oriented Programming with Laravel - Session 1Object Oriented Programming with Laravel - Session 1
Object Oriented Programming with Laravel - Session 1
 

Kürzlich hochgeladen

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 

Object Oriented Programming with Laravel - Session 5

  • 1. Object-Oriented Programming (with Laravel) By: Shahrzad Peyman Session 5 May-2017 shahrzad.peymaan@gmail.com 1
  • 2. 2 Today’s Presentation • DataBase • Configuration • Multiple Connection • Raw Queries • Query Builder • Pagination
  • 3. 3 DataBase Laravel makes interacting with databases extremely simple across a variety of database backends using either raw SQL, the fluent query builder, and the Eloquent ORM. Currently, Laravel supports four databases: • MySQL • Postgres • SQLite • SQL Server
  • 4. Configuration 4 The database configuration for your application is located at config/database.php. In this file you may define all of your database connections, as well as specify which connection should be used by default. Examples for most of the supported database systems are provided in this file.
  • 5. Using Multiple DataBase Connection 5 When using multiple connections, you may access each connection via the connection method on th DB facade. The name passed to the connection method should correspond to one of the connections listed in your config/ database.php configuration file:
  • 6. 6 Running Raw SQL Queries Once you have configured your database connection, you may run queries using the DB facade. The DB facade provides methods for each type of query: select, update, insert, delete, and statement.
  • 8. 8 Running a Select Query The first argument passed to the select method is the raw SQL query, while the second argument is any parameter bindings that need to be bound to the query. Typically, these are the values of the where clause constraints. The select method will always return an array of results.
  • 10. Running a General Statement 10 Some database statements do not return any value. For these types of operations, you may use the statement method on the DB facade:
  • 11. DataBase Transactions You may use the transaction method on the DB facade to run a set of operations within a database transaction. If an exception is thrown within the transaction Closure, the transaction will automatically be rolled back. If the Closure executes successfully, the transaction will automatically be committed. You don't need to worry about manually rolling back or committing while using the transaction method:
  • 13. Query Builder Laravel's database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application and works on all supported database systems.
  • 14. Retrieving All Rows From A Table 14
  • 15. 15 The get method returns an IlluminateSupportCollection containing the results where each result is an instance of the PHP StdClass object. You may access each column's value by accessing the column as a property of the object: Retrieving All Rows From A Table
  • 16. Retrieving A Single Row / Column From A Table 16
  • 17. Retrieving A List Of Column Values 17
  • 18. Aggregates 18 The query builder also provides a variety of aggregate methods such as count, max, min, avg, and sum. You may call any of these methods after constructing your query:
  • 20. 20 Raw Expressions Sometimes you may need to use a raw expression in a query. These expressions will be injected into the query as strings, so be careful not to create any SQL injection points! To create a raw expression, you may use the DB:raw method:
  • 21. 21 Inner Join The query builder may also be used to write join statements. To perform a basic "inner join", you may use the join method on a query builder instance. The first argument passed to the join method is the name of the table you need to join to, while the remaining arguments specify the column constraints for the join. Of course, as you can see, you can join to multiple tables in a single query:
  • 22. 22 Left Join If you would like to perform a "left join" instead of an "inner join", use the leftJoin method. The leftJoin method has the same signature as the join method:
  • 23. Cross Join 23 To perform a "cross join" use the crossJoin method with the name of the table you wish to cross join to. Cross joins generate a cartesian product between the first table and the joined table:
  • 25. 25 Unions The query builder also provides a quick way to "union" two queries together. For example, you may create an initial query and use the union method to union it with a second query: 25
  • 26. 26 Where Clauses You may use the where method on a query builder instance to add where clauses to the query. The most basic call to where requires three arguments. The first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators. Finally, the third argument is the value to evaluate against the column.
  • 31. 31 Parameters Grouping Sometimes you may need to create more advanced where clauses such as "where exists" clauses or nested parameter groupings. The Laravel query builder can handle these as well. To get started, let's look at an example of grouping constraints within parenthesis
  • 35. 35 Conditional Clauses Sometimes you may want clauses to apply to a query only when something else is true. For instance you may only want to apply a where statement if a given input value is present on the incoming request. You may accomplish this using the when method:
  • 40. 40 Pagination In other frameworks, pagination can be very painful. Laravel's paginator is integrated with the query builder and Eloquent ORM and provides convenient, easy-to-use pagination of database results out of the box. The HTML generated by the paginator is compatible with the Bootstrap CSS framework. There are several ways to paginate items. The simplest is by using the paginate method on the query builder or an Eloquent query. The paginate method automatically takes care of setting the proper limit and offset based on the current page being viewed by the user. By default, the current page is detected by the value of the page query string argument on the HTTP request. Of course, this value is automatically detected by Laravel, and is also automatically inserted into links generated by the paginator.
  • 43. 43 Customize the Pagination View By default, the views rendered to display the pagination links are compatible with the Bootstrap CSS framework. However, if you are not using Bootstrap, you are free to define your own views to render these links. When calling the link method on a paginator instance, pass the view name as the first argument to the method: