FindBy…
findBy…( string $arg1 [, string $arg2, ...] )
The findBy…() magic method allows you to incorporate a where statement into the method name. To do this, simply start the method off as findBy followed by the column name (first letter uppercase). To add additional parameters, append AndBy or OrBy and the next column name. For the arguments, simply place the column values you would like to filter by, in order as setup in the method.
1 2 3 4 5 6 7 8 |
// Find All by Name WHERE Name = Joe
DB::MySQL()->table('myTable')->findByName('Joe'); // Find All by Name WHERE Name = Joe OR Bob
DB::MySQL()->table('myTable')->findByNameOrByName('Joe', 'Bob'); // Find All by Name And Age
DB::MySQL()->table('myTable')->findByNameAndByAge('Joe', '99'); |
Because the magic findBy…() method utilizes the fetch() method, the limit() method can be used and will be respected. For example:
1 2 |
// Return 10 records
DB::MySQL()->table('myTable')->limit(10)->findByName('Joe'); |