I'm coding a query :
$result = \DB::table('order_items as oi')
->selectRaw(
'order_item_type as item_type,
order_item_id as item_id,
if(order_item_type = "App\\\Models\\\Book", oi.price, invoices.price) as price
)
just note to if statement, I'm having to use two escape character or query doesnt match App\Models\Book. when i inspect output query by laravel debugger its :
select order_item_type as item_type,
order_item_id as item_id,
if(order_item_type = "App\\Models\\Book", oi.price, invoices.price) as price,...
whats happen here? does laravel query builder remove one slash and then mysql engine remove the second slash in run time ?
EDIT :
But somewhere else in the same query i have a where clause that i used one escape character and it works fine:
->leftjoin('books', function ($q) {
$q->on('q3.order_item_id', '=', 'books.id')
->where('q3.order_item_type', '=', 'App\\Models\\Book');
})
and the output query part by laravel debugger:
left join `books` on `q3`.`order_item_id` = `books`.`id` and
`q3`.`order_item_type` = 'App\Models\Book'
Can anyone explain why in if i must use two escape character but in join only one escape character is needed?
in fact there would be no problem if i even don't use any escape character in where query builder method and write the code as:
->leftjoin('books', function ($q) {
$q->on('q3.order_item_id', '=', 'books.id')
->where('q3.order_item_type', '=', 'App\Models\Book');
})