Laravel Course

Laravel's database query builder provides a convenient, fluent interface to creating and running database queries.
- It uses PDO parameter binding to protect your application against SQL injection. There is no need to clean strings passed as bindings.

Joins

To perform a basic "inner join", you may use the join() method on a query builder instance.
The first argument is the name of the table you need to join to; the remaining arguments specify the relation of the columns for the join.
- You can join to multiple tables in a single query:
$users = DB::table('users')
 ->join('contacts', 'users.id', '=', 'contacts.user_id')
 ->join('orders', 'users.id', '=', 'orders.user_id')
 ->select('users.*', 'contacts.email', 'orders.price')
->get();
- To perform a "left join" query, use the leftJoin() method, in the same way as the join() method.
$users = DB::table('users')
 ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->get();

Unions

To "union" two queries together, create an initial query and use the union() method to union it with a second query.
$first = DB::table('users')->whereNull('first_name');

$users = DB::table('users')->whereNull('last_name')
->union($first)->get();


- Documentation: Laravel - Database: Query Builder

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which meta tag provides a short description of the page?
<meta content="..."> <meta description="..."> <meta http-equiv="...">
<meta name="description" content="70-160 characters that describes the content of the page" />
Which CSS property is used to stop the wrapping effect of the "float"?
clear text-align position
#some_id {
  clear: both;
}
Click on the method which gets an array with all the elements in the document that have a specified tag name.
getElementsByName() getElementById() getElementsByTagName()
var divs = document.getElementsByTagName("div");
var nr_divs = divs.length;
alert(nr_divs);
Indicate the PHP function which returns the number of elements in array.
is_[) count() strlen()
$arr =[7, 8, "abc", 10);
$nri = count($arr);
echo $nri;        // 4
MySQL Database, Query Builder: Join and Union

Last accessed pages

  1. PHP Strings (3263)
  2. Selection Tools (8145)
  3. Get Lower, Higher, and Closest Number (5342)
  4. Simple Admin Login PHP Script (10894)
  5. jQuery parent, children and nth-child() (13826)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (201)
  2. Read Excel file data in PHP - PhpExcelReader (66)
  3. The Mastery of Love (56)
  4. PHP Unzipper - Extract Zip, Rar Archives (51)
  5. Working with MySQL Database (34)
Chat
Chat or leave a message for the other users
Full screenInchide