Sequential execution of DB class methods:
DB::table('users') - the table method is executed, will return an instance of the DB class for building a database query associated with the users table;->select('name','surname') - the select method is executed with variable length arguments;->where('id', $userId) - the where method is executed with variable length arguments;->get() - the get method is executed that forms the query and receives the results.
In paragraphs 1, 2, 3, an instance of the DB class ( object() ) is returned to build a query to the database. Most likely, when executing these methods, the DB class variables are assigned corresponding values for the query, which are then used to construct the query during execution ->get() .
UPD - useful links
As rightly pointed out by @Deonis, this implementation is called a " fluent interface (fluent interface) ".
Useful links with examples and descriptions:
- Wikipedia - Fluent interface
- Habrahabr - Flowing Interface Programming Template in PHP
- Habrahabr - “Advanced Flow Interface”
- Habrahabr - “Design Patterns with a Human Face”
tablereturns an object, thenselecton this object returns an object, thenwhere, at the end, thegetmethod is called on the object that returnedwhere. - Suvitruf ♦