How with, where operators work in Laravel?
How do with, where
eloquent operators work in Laravel?
Is it possible to see is build result SQL query after using with
, where
or these operators applied only for result data model?
Does with(<related model>)
operator work as INNER JOIN?
Where to explore information about that?
laravel laravel-5
add a comment |
How do with, where
eloquent operators work in Laravel?
Is it possible to see is build result SQL query after using with
, where
or these operators applied only for result data model?
Does with(<related model>)
operator work as INNER JOIN?
Where to explore information about that?
laravel laravel-5
Try using a good ide like PHPStorm and following the method to understand how it works.
– Elias Soares
Nov 14 '18 at 0:52
add a comment |
How do with, where
eloquent operators work in Laravel?
Is it possible to see is build result SQL query after using with
, where
or these operators applied only for result data model?
Does with(<related model>)
operator work as INNER JOIN?
Where to explore information about that?
laravel laravel-5
How do with, where
eloquent operators work in Laravel?
Is it possible to see is build result SQL query after using with
, where
or these operators applied only for result data model?
Does with(<related model>)
operator work as INNER JOIN?
Where to explore information about that?
laravel laravel-5
laravel laravel-5
asked Nov 14 '18 at 0:40
OPVOPV
1,54721335
1,54721335
Try using a good ide like PHPStorm and following the method to understand how it works.
– Elias Soares
Nov 14 '18 at 0:52
add a comment |
Try using a good ide like PHPStorm and following the method to understand how it works.
– Elias Soares
Nov 14 '18 at 0:52
Try using a good ide like PHPStorm and following the method to understand how it works.
– Elias Soares
Nov 14 '18 at 0:52
Try using a good ide like PHPStorm and following the method to understand how it works.
– Elias Soares
Nov 14 '18 at 0:52
add a comment |
4 Answers
4
active
oldest
votes
To know the SQL Query that Laravel execute you can use the toSql()
function:
$results = User::where(function($q) use ($request) {
$q->orWhere('email', 'like', '%john@example.org%');
$q->orWhere('first_name', 'like', '%John%');
$q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results); // output
Check this article for more information regarding this aspect. There is also another alternative to this approach.
Regarding your next question: No, Laravel doesn't do JOIN
s. You can read a little bit about this regard in this article.
PD: If you want to know more about how Eloquent work, you can follow this good Laracasts series.
add a comment |
Since using with()
will result in multiple SQL statements being ran, a good way to understand the underlying SQL is to use DB::enableQueryLog()
and DB::getQueryLog()
.
add a comment |
According to SQL above you want to find Product with the name $needle
or manufacturer name $needle
. Guess You need whereHas
Method.
$products = Product::with("manufacturer")
->whereHas('manufacturer',function($query) use ($needle){
$query->where("name","like","%{$needle}%");
})
->orWhere("name","like","%{$needle}%")->get();
You can also prepend it to "with" method with the same query condition to obtain the relation instance it matched. In case of belongsTo you can use it without specifying condition.
Check out querying relations: https://laravel.com/docs/5.5/eloquent-relationships#querying-relations
add a comment |
There are two ways to get detailed info regarding with and where condition:
- use Laravel debug bar in the development environment to see detailed info regarding queries. What's the structure, frequencies of queries etc.
- Use toSql function to dump query
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291535%2fhow-with-where-operators-work-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
To know the SQL Query that Laravel execute you can use the toSql()
function:
$results = User::where(function($q) use ($request) {
$q->orWhere('email', 'like', '%john@example.org%');
$q->orWhere('first_name', 'like', '%John%');
$q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results); // output
Check this article for more information regarding this aspect. There is also another alternative to this approach.
Regarding your next question: No, Laravel doesn't do JOIN
s. You can read a little bit about this regard in this article.
PD: If you want to know more about how Eloquent work, you can follow this good Laracasts series.
add a comment |
To know the SQL Query that Laravel execute you can use the toSql()
function:
$results = User::where(function($q) use ($request) {
$q->orWhere('email', 'like', '%john@example.org%');
$q->orWhere('first_name', 'like', '%John%');
$q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results); // output
Check this article for more information regarding this aspect. There is also another alternative to this approach.
Regarding your next question: No, Laravel doesn't do JOIN
s. You can read a little bit about this regard in this article.
PD: If you want to know more about how Eloquent work, you can follow this good Laracasts series.
add a comment |
To know the SQL Query that Laravel execute you can use the toSql()
function:
$results = User::where(function($q) use ($request) {
$q->orWhere('email', 'like', '%john@example.org%');
$q->orWhere('first_name', 'like', '%John%');
$q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results); // output
Check this article for more information regarding this aspect. There is also another alternative to this approach.
Regarding your next question: No, Laravel doesn't do JOIN
s. You can read a little bit about this regard in this article.
PD: If you want to know more about how Eloquent work, you can follow this good Laracasts series.
To know the SQL Query that Laravel execute you can use the toSql()
function:
$results = User::where(function($q) use ($request) {
$q->orWhere('email', 'like', '%john@example.org%');
$q->orWhere('first_name', 'like', '%John%');
$q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results); // output
Check this article for more information regarding this aspect. There is also another alternative to this approach.
Regarding your next question: No, Laravel doesn't do JOIN
s. You can read a little bit about this regard in this article.
PD: If you want to know more about how Eloquent work, you can follow this good Laracasts series.
edited Nov 14 '18 at 0:57
answered Nov 14 '18 at 0:51
HCKHCK
3,50211035
3,50211035
add a comment |
add a comment |
Since using with()
will result in multiple SQL statements being ran, a good way to understand the underlying SQL is to use DB::enableQueryLog()
and DB::getQueryLog()
.
add a comment |
Since using with()
will result in multiple SQL statements being ran, a good way to understand the underlying SQL is to use DB::enableQueryLog()
and DB::getQueryLog()
.
add a comment |
Since using with()
will result in multiple SQL statements being ran, a good way to understand the underlying SQL is to use DB::enableQueryLog()
and DB::getQueryLog()
.
Since using with()
will result in multiple SQL statements being ran, a good way to understand the underlying SQL is to use DB::enableQueryLog()
and DB::getQueryLog()
.
answered Nov 14 '18 at 0:58
bradforbesbradforbes
39617
39617
add a comment |
add a comment |
According to SQL above you want to find Product with the name $needle
or manufacturer name $needle
. Guess You need whereHas
Method.
$products = Product::with("manufacturer")
->whereHas('manufacturer',function($query) use ($needle){
$query->where("name","like","%{$needle}%");
})
->orWhere("name","like","%{$needle}%")->get();
You can also prepend it to "with" method with the same query condition to obtain the relation instance it matched. In case of belongsTo you can use it without specifying condition.
Check out querying relations: https://laravel.com/docs/5.5/eloquent-relationships#querying-relations
add a comment |
According to SQL above you want to find Product with the name $needle
or manufacturer name $needle
. Guess You need whereHas
Method.
$products = Product::with("manufacturer")
->whereHas('manufacturer',function($query) use ($needle){
$query->where("name","like","%{$needle}%");
})
->orWhere("name","like","%{$needle}%")->get();
You can also prepend it to "with" method with the same query condition to obtain the relation instance it matched. In case of belongsTo you can use it without specifying condition.
Check out querying relations: https://laravel.com/docs/5.5/eloquent-relationships#querying-relations
add a comment |
According to SQL above you want to find Product with the name $needle
or manufacturer name $needle
. Guess You need whereHas
Method.
$products = Product::with("manufacturer")
->whereHas('manufacturer',function($query) use ($needle){
$query->where("name","like","%{$needle}%");
})
->orWhere("name","like","%{$needle}%")->get();
You can also prepend it to "with" method with the same query condition to obtain the relation instance it matched. In case of belongsTo you can use it without specifying condition.
Check out querying relations: https://laravel.com/docs/5.5/eloquent-relationships#querying-relations
According to SQL above you want to find Product with the name $needle
or manufacturer name $needle
. Guess You need whereHas
Method.
$products = Product::with("manufacturer")
->whereHas('manufacturer',function($query) use ($needle){
$query->where("name","like","%{$needle}%");
})
->orWhere("name","like","%{$needle}%")->get();
You can also prepend it to "with" method with the same query condition to obtain the relation instance it matched. In case of belongsTo you can use it without specifying condition.
Check out querying relations: https://laravel.com/docs/5.5/eloquent-relationships#querying-relations
edited Nov 14 '18 at 14:47
HCK
3,50211035
3,50211035
answered Nov 14 '18 at 3:21
Ismoil ShifoevIsmoil Shifoev
1,425812
1,425812
add a comment |
add a comment |
There are two ways to get detailed info regarding with and where condition:
- use Laravel debug bar in the development environment to see detailed info regarding queries. What's the structure, frequencies of queries etc.
- Use toSql function to dump query
add a comment |
There are two ways to get detailed info regarding with and where condition:
- use Laravel debug bar in the development environment to see detailed info regarding queries. What's the structure, frequencies of queries etc.
- Use toSql function to dump query
add a comment |
There are two ways to get detailed info regarding with and where condition:
- use Laravel debug bar in the development environment to see detailed info regarding queries. What's the structure, frequencies of queries etc.
- Use toSql function to dump query
There are two ways to get detailed info regarding with and where condition:
- use Laravel debug bar in the development environment to see detailed info regarding queries. What's the structure, frequencies of queries etc.
- Use toSql function to dump query
answered Nov 14 '18 at 15:29
Software developerSoftware developer
313
313
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291535%2fhow-with-where-operators-work-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try using a good ide like PHPStorm and following the method to understand how it works.
– Elias Soares
Nov 14 '18 at 0:52