Answer the question
In order to leave comments, you need to log in
Eloquent. Show request without "?", but with substituted values?
Hello. How to show query in Eloquern without "?", but with substituted values?
Those. if you display a query using the toSql() function, then instead of the substituted where values, it indicates ?
.
For example, I have a request that is correctly formed, but for some reason does not work.
Works:
select *
from `users`
inner join `pro_payments`
on `users`.`id` = `pro_payments`.`user_id`
and (`pro_payments`.`start` < NOW()
and `pro_payments`.`end` > NOW()
and `pro_payments`.`active` = 1
)
where `group_id` = 2
and `users`.`deleted_at` is null
public function scopeWithPayment($query){
return $query->join('pro_payments', function($join){
$join->on('users.id', '=', 'pro_payments.user_id')
->where(function($sql){
$sql->where('pro_payments.start', '<', DB::raw('now()'))
->where('pro_payments.end', '>', DB::raw('now()'))
->where('pro_payments.active', '=', 1);
});
});
}
public function scopeProviders($query){
return $query->where('group_id', 2);
}
User::providers()->withPayment()->toSql()
select * from `users` inner join `pro_payments` on `users`.`id` = `pro_payments`.`user_id` and (`pro_payments`.`start` < ? and `pro_payments`.`end` > ? and `pro_payments`.`active` = ?) where `group_id` = ? and `users`.`deleted_at` is null
Answer the question
In order to leave comments, you need to log in
You can write DB::enableQueryLog() before the request, and after the request do dd(DB::getQueryLog())
This will show all requests + data that were used (the data will be separate).
You can also install Laravel Debugbar - a very convenient debugger and not only for sql queries.
alternatively watch all requests via
https://github.com/itsgoingd/clockwork-chrome
And why don't you want to use ORM, but just use a Queri Builder from it? It would return you a beautiful object, not game after join.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question