laravel orm mult where will cover condition
up vote
0
down vote
favorite
my code is:
$type = 10;
$logMp = new SendLog();
$keyword && $logMp->where('msg', 'like', "%{$keyword}%");
$type && $logMp->where(['type' => $type]);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->paginate($size, ['*'], 'page', $page)->toArray();
after i change the code to :
$logMp = new SendLog();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
print_r($logs);die;
for easy to dump the sql,
however , the sql is always like
select * from `send_log` where (`group_id` = ?) order by `id` desc
and as you can see , the type params is disppear, how can i handle this?
php laravel orm
add a comment |
up vote
0
down vote
favorite
my code is:
$type = 10;
$logMp = new SendLog();
$keyword && $logMp->where('msg', 'like', "%{$keyword}%");
$type && $logMp->where(['type' => $type]);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->paginate($size, ['*'], 'page', $page)->toArray();
after i change the code to :
$logMp = new SendLog();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
print_r($logs);die;
for easy to dump the sql,
however , the sql is always like
select * from `send_log` where (`group_id` = ?) order by `id` desc
and as you can see , the type params is disppear, how can i handle this?
php laravel orm
why$keyword &&
and$type &&
? Maybe the problem is here..
– Sand Of Vega
Nov 19 at 18:03
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
my code is:
$type = 10;
$logMp = new SendLog();
$keyword && $logMp->where('msg', 'like', "%{$keyword}%");
$type && $logMp->where(['type' => $type]);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->paginate($size, ['*'], 'page', $page)->toArray();
after i change the code to :
$logMp = new SendLog();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
print_r($logs);die;
for easy to dump the sql,
however , the sql is always like
select * from `send_log` where (`group_id` = ?) order by `id` desc
and as you can see , the type params is disppear, how can i handle this?
php laravel orm
my code is:
$type = 10;
$logMp = new SendLog();
$keyword && $logMp->where('msg', 'like', "%{$keyword}%");
$type && $logMp->where(['type' => $type]);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->paginate($size, ['*'], 'page', $page)->toArray();
after i change the code to :
$logMp = new SendLog();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
print_r($logs);die;
for easy to dump the sql,
however , the sql is always like
select * from `send_log` where (`group_id` = ?) order by `id` desc
and as you can see , the type params is disppear, how can i handle this?
php laravel orm
php laravel orm
edited Nov 19 at 18:12
asked Nov 19 at 17:59
Jack he
144
144
why$keyword &&
and$type &&
? Maybe the problem is here..
– Sand Of Vega
Nov 19 at 18:03
add a comment |
why$keyword &&
and$type &&
? Maybe the problem is here..
– Sand Of Vega
Nov 19 at 18:03
why
$keyword &&
and $type &&
? Maybe the problem is here..– Sand Of Vega
Nov 19 at 18:03
why
$keyword &&
and $type &&
? Maybe the problem is here..– Sand Of Vega
Nov 19 at 18:03
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
$type && $logMp->where('type', $type);
OR
$type && $logMp->where([['type' ,'=', $type]]);
Is this your original code? As setting the $type then using it as an operator for the where doesn't really make sense.
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
add a comment |
up vote
0
down vote
Try to use query()
function instead of creating a new object:
$logMp = SendLog::query();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
$type && $logMp->where('type', $type);
OR
$type && $logMp->where([['type' ,'=', $type]]);
Is this your original code? As setting the $type then using it as an operator for the where doesn't really make sense.
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
add a comment |
up vote
0
down vote
$type && $logMp->where('type', $type);
OR
$type && $logMp->where([['type' ,'=', $type]]);
Is this your original code? As setting the $type then using it as an operator for the where doesn't really make sense.
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
add a comment |
up vote
0
down vote
up vote
0
down vote
$type && $logMp->where('type', $type);
OR
$type && $logMp->where([['type' ,'=', $type]]);
Is this your original code? As setting the $type then using it as an operator for the where doesn't really make sense.
$type && $logMp->where('type', $type);
OR
$type && $logMp->where([['type' ,'=', $type]]);
Is this your original code? As setting the $type then using it as an operator for the where doesn't really make sense.
answered Nov 19 at 18:05
Matt Nelson
11
11
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
add a comment |
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
the $type is a params from frontend, , and I has dump the $type , and make sure it has value 2
– Jack he
Nov 19 at 18:14
add a comment |
up vote
0
down vote
Try to use query()
function instead of creating a new object:
$logMp = SendLog::query();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
add a comment |
up vote
0
down vote
Try to use query()
function instead of creating a new object:
$logMp = SendLog::query();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
add a comment |
up vote
0
down vote
up vote
0
down vote
Try to use query()
function instead of creating a new object:
$logMp = SendLog::query();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
Try to use query()
function instead of creating a new object:
$logMp = SendLog::query();
$type = 2;
$logMp->where('type', $type);
$logs = $logMp->where('group_id', $groupId)->orderBy('id', 'desc')->toSql();
answered Nov 19 at 19:45
Laerte
5,11132040
5,11132040
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53380252%2flaravel-orm-mult-where-will-cover-condition%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
why
$keyword &&
and$type &&
? Maybe the problem is here..– Sand Of Vega
Nov 19 at 18:03