-
-
Save wadson-pereira/fd32c4b6315f93377968bafdc424dc70 to your computer and use it in GitHub Desktop.
Bind parameters into the SQL query for Laravel ORM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class MyModel extends Eloquent { | |
| public function getSql() | |
| { | |
| $builder = $this->getBuilder(); | |
| $sql = $builder->toSql(); | |
| foreach($builder->getBindings() as $binding) | |
| { | |
| $value = is_numeric($binding) ? $binding : "'".$binding."'"; | |
| $sql = preg_replace('/\?/', $value, $sql, 1); | |
| } | |
| return $sql; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment