This query constructor is quite a powerful tool for building and executing SQL queries. You can also direct it to filter, sort and merge tables. For example:

    1. DB::table('users')
    2. ->join('contacts', function ($join) {
    3. $join->on('users.id', '=', 'contacts.user_id')->orOn(...);

    Nevertheless, models are more convenient to work with. You can find the description of Eloquent ORM models and the syntax for querying them at .

    This query will return the first 20 customers sorted alphabetically:

    1. $customers = App\Customer::select()
    2. ->orderBy('name')
    3. ->take(20)

    When a model is more complex, its relationships or relationship collections can be retrieved via dynamic attributes. The following query, for example, returns the items of the invoice that has the identifier 1:

    1. $flight = new Flight;
    2. $flight->name = $request->name;
    3. $flight->save();

    Updating a record involves finding it, accepting changes to the appropriate attributes and saving it with the save method:

    The method allows a record to be deleted more rapidly by its key value, without needing to retrieve its instance:

    1. App\Flight::destroy(1);