ali_254 Posted April 7, 2022 Share Posted April 7, 2022 (edited) hi. When we use the following commands to Join to another table: return $this->belongsTo(Category::class,'cat_id','id'); How can I see the real query? I want to see the query produced by Eloquent orm Edited April 7, 2022 by ali_254 Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/ Share on other sites More sharing options...
requinix Posted April 7, 2022 Share Posted April 7, 2022 Look for a toSql() method, or Eloquent has a query log you can enable. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595132 Share on other sites More sharing options...
ali_254 Posted April 7, 2022 Author Share Posted April 7, 2022 13 minutes ago, requinix said: Look for a toSql() method, or Eloquent has a query log you can enable. Thanks a lot... How can I see it? please explain more... Can you write an example? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595134 Share on other sites More sharing options...
requinix Posted April 7, 2022 Share Posted April 7, 2022 https://www.google.com/search?q=eloquent+enable+query+log 1 Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595135 Share on other sites More sharing options...
ali_254 Posted April 8, 2022 Author Share Posted April 8, 2022 thanks... Also, does this command also produce a query? return $this->belongsTo(Category::class,'cat_id','id'); Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595151 Share on other sites More sharing options...
ali_254 Posted April 8, 2022 Author Share Posted April 8, 2022 I understand, thank you Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595156 Share on other sites More sharing options...
maxxd Posted April 8, 2022 Share Posted April 8, 2022 Beyond requinix's advice, https://github.com/barryvdh/laravel-debugbar is a popular package that helps with Laravel development. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595158 Share on other sites More sharing options...
ali_254 Posted April 8, 2022 Author Share Posted April 8, 2022 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/314678-how-can-i-see-the-generated-query-in-models/#findComment-1595164 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.