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 attribute is used in <img> tag for the address of the image?
href src rel
<img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Which CSS code hides the element on page?
display: none; display: inline; position: relative;
#id {
  display: none;
}
What instruction stops the execution of a while() or for() statement?
continue prompt() break
for(var i = 0; i< 8; i++) {
  if(i > 1) break;
  alert(i);
}
Indicate the function that can create a constant.
define() include() defined()
define("CONSTANT_NAME", "value");
echo CONSTANT_NAME;
MySQL Database, Query Builder: Join and Union

Last accessed pages

  1. Moving html element to a random direction (5060)
  2. innerHTML in PHP (16884)
  3. Register and show online users and visitors (39342)
  4. Execute JavaScript scripts loaded via AJAX (7824)
  5. Replace JavaScript variable name from string with its value (3446)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (470)
  2. Read Excel file data in PHP - PhpExcelReader (147)
  3. PHP Unzipper - Extract Zip, Rar Archives (145)
  4. SHA1 Encrypt data in JavaScript (122)
  5. Get and Modify content of an Iframe (108)
Chat
Chat or leave a message for the other users
Full screenInchide