using toSql()
Method Illuminate\Database\Eloquent\Collection::toSql does not exist
$range = ProductCategory::whereIn('id', $categoryIds)
->translatedIn('en')->get();
dd($range->toSql());
I want to see the result of the sql but unable to do so. Even after I delete the ->get(); still does not works.
ref: http://mydoubts.in/blog/tag/tosql-not-working-in-laravel/
Any clue why?
@davy_yg
try this-
ProductCategory::whereIn('id', $categoryIds)
->translatedIn('en')->toSql();
The range is a collection of the result returned from the query. You need to do the toSqlon the query.
So try
dd( ProductCategory::whereIn('id', $categoryIds)
->translatedIn('en')->toSql());
This is old, but you forgot to add query(), so it will be
$range = ProductCategory::query()->whereIn('id', $categoryIds)
->translatedIn('en') ;
dd($range->toSql());
@Snapey Also instead of:
dd(...->translatedIn('en')->toSql());
You can chain the dd() call:
...->translatedIn('en')->dd();
Don't know if this is common knowledge, I just recently found out myself.
Please or to participate in this conversation.