1. Go to this page and download the library: Download lyhty/macros library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lyhty / macros example snippets
$query = User::query()->selectKey();
$query->toSql(); // "select `id` from `users`"
$query = User::query()
->whereLike('name', 'Matti Suo', 'right')
->orWhereLike('name', 'ranie')
->orWhereLike('name', 'mi', 'left');
$query->toSql();
// "select * from `users` where (`users`.`name` LIKE ?) or (`users`.`name` LIKE ?) or (`users`.`name` LIKE ?)"
// First ? being "Matti Suo%", second "%ranie%" and third "%mi"
$query = User::query()->whereLike('games.name', 'Apex Leg', 'right');
$query->toSql();
// select * from `users` where (exists
// (select * from `games` where `users`.`id` = `games`.`user_id` and `games`.`name` LIKE ?)
// )
// ? being "Apex Leg%"
$query = User::query()->whereLike(['games.console.name', 'games.platforms.name'], 'Xbox');
$query->toSql();
// select * from `users` where (exists (select * from `games` where `users`.`id` = `games`.`user_id` and (exists
// (select * from `consoles` where `games`.`console_id` = `consoles`.`id` and (`consoles`.`name` LIKE ?)) or exists
// (select * from `platforms` inner join `platform_game` on `platforms`.`id` = `platform_game`.`platform_id` where
// `games`.`id` = `platform_game`.`game_id` and (`platforms`.`name` LIKE ?)))))
// ? being "Xbox"