How can I “where” raw column(DB::raw). [LARAVEL]Laravel Eloquent Select CASE?add a temporary column in SQL, where the values depend from another columnUnable to Get Eloquent to Automatically Create JoinsLaravel requires the Mcrypt PHP extensionLaravel 4 Eloquent Query Using WHERE with OR AND OR?How to Create Multiple Where Clause Query Using Laravel Eloquent?Laravel vue cannot access to relation dataAccessing data separately from multiple tables in single view in blade template laravelHow to store auth::user profile data into Laravel view?Laravel inner join column not foundHow to query laravel collection resultHow to reuse the jquery ajax post request, that is already working, to the autocomplete functionality?
Is there any good reason to write "it is easy to see"?
Is the seat-belt sign activation when a pilot goes to the lavatory standard procedure?
How to rename multiple files in a directory at the same time
Why is the marginal distribution/marginal probability described as "marginal"?
Should I communicate in my applications that I'm unemployed out of choice rather than because nobody will have me?
Is there an academic word that means "to split hairs over"?
Could a space colony 1g from the sun work?
I recently started my machine learning PhD and I have absolutely no idea what I'm doing
Cuban Primes
Capital gains on stocks sold to take initial investment off the table
Would life always name the light from their sun "white"
Using chord iii in a chord progression (major key)
What is the effect of the Feeblemind spell on Ability Score Improvements?
Why does SSL Labs now consider CBC suites weak?
Promotion comes with unexpected 24/7/365 on-call
Understanding Deutch's Algorithm
Formal Definition of Dot Product
Why did the soldiers of the North disobey Jon?
Which creature is depicted in this Xanathar's Guide illustration of a war mage?
What do you call the hair or body hair you trim off your body?
Do people who work at research institutes consider themselves "academics"?
Polynomial division: Is this trick obvious?
Will consteval functions allow template parameters dependent on function arguments?
Does the wearer know what items are in which patch in the Robe of Useful items?
How can I “where” raw column(DB::raw). [LARAVEL]
Laravel Eloquent Select CASE?add a temporary column in SQL, where the values depend from another columnUnable to Get Eloquent to Automatically Create JoinsLaravel requires the Mcrypt PHP extensionLaravel 4 Eloquent Query Using WHERE with OR AND OR?How to Create Multiple Where Clause Query Using Laravel Eloquent?Laravel vue cannot access to relation dataAccessing data separately from multiple tables in single view in blade template laravelHow to store auth::user profile data into Laravel view?Laravel inner join column not foundHow to query laravel collection resultHow to reuse the jquery ajax post request, that is already working, to the autocomplete functionality?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
My Objective for these, is to make an autocomplete input text for location. When I type something like 'streetNo', 'city' or 'country' relevant data should return
I just created a raw column "full_address" joining "streetNo", "city", & "country" column.
Heres my code:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country',
DB::raw("(CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)) AS full_address")
)
->where('full_address', 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
I tried to search existing data like "city or country" but no data returned. I suspect there something wrong of "where-ing" the data.
Question is can we "where" temporary column like "full_address column" like the code shown above?? Because I tried that code and no data returned when there is actually
Need your help, Sirs..
laravel
|
show 6 more comments
My Objective for these, is to make an autocomplete input text for location. When I type something like 'streetNo', 'city' or 'country' relevant data should return
I just created a raw column "full_address" joining "streetNo", "city", & "country" column.
Heres my code:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country',
DB::raw("(CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)) AS full_address")
)
->where('full_address', 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
I tried to search existing data like "city or country" but no data returned. I suspect there something wrong of "where-ing" the data.
Question is can we "where" temporary column like "full_address column" like the code shown above?? Because I tried that code and no data returned when there is actually
Need your help, Sirs..
laravel
You have to combineCASE
. Check this answer to get an idea.
– Tpojka
Mar 23 at 16:00
When you say not working does the query fail or are you not getting data you're expecting and if it's the 2nd case can you share some data you'd expect to get but are not getting along with a query?
– apokryfos
Mar 23 at 16:06
@apokryfos already edited my question Sir. Could you mine to read it again, thanks Sir.
– escbooster12
Mar 23 at 18:26
@Tpojka thanks for reply Sir. Sir I'm not using "CASE WHEN", I'm just using "CONCAT".
– escbooster12
Mar 23 at 18:29
1
I am telling you how I would approach to that problem. Again, check two links I found on site for you and study it for a bit. You can't search something that doesn't exist. And temporary column doesn't exist. You should make/return one to have it for checking against comparing part. But what you can is to return only rows that comply to that case as I proposed you to do. You should try it with raw query first and after you have working query, only then try to convert to eloquent query builder.->where('full_address', 'LIKE', "%$searchAddress%")
won't work but try with raw query first.
– Tpojka
Mar 23 at 18:57
|
show 6 more comments
My Objective for these, is to make an autocomplete input text for location. When I type something like 'streetNo', 'city' or 'country' relevant data should return
I just created a raw column "full_address" joining "streetNo", "city", & "country" column.
Heres my code:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country',
DB::raw("(CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)) AS full_address")
)
->where('full_address', 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
I tried to search existing data like "city or country" but no data returned. I suspect there something wrong of "where-ing" the data.
Question is can we "where" temporary column like "full_address column" like the code shown above?? Because I tried that code and no data returned when there is actually
Need your help, Sirs..
laravel
My Objective for these, is to make an autocomplete input text for location. When I type something like 'streetNo', 'city' or 'country' relevant data should return
I just created a raw column "full_address" joining "streetNo", "city", & "country" column.
Heres my code:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country',
DB::raw("(CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)) AS full_address")
)
->where('full_address', 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
I tried to search existing data like "city or country" but no data returned. I suspect there something wrong of "where-ing" the data.
Question is can we "where" temporary column like "full_address column" like the code shown above?? Because I tried that code and no data returned when there is actually
Need your help, Sirs..
laravel
laravel
edited Mar 24 at 7:02
escbooster12
asked Mar 23 at 15:19
escbooster12escbooster12
1669
1669
You have to combineCASE
. Check this answer to get an idea.
– Tpojka
Mar 23 at 16:00
When you say not working does the query fail or are you not getting data you're expecting and if it's the 2nd case can you share some data you'd expect to get but are not getting along with a query?
– apokryfos
Mar 23 at 16:06
@apokryfos already edited my question Sir. Could you mine to read it again, thanks Sir.
– escbooster12
Mar 23 at 18:26
@Tpojka thanks for reply Sir. Sir I'm not using "CASE WHEN", I'm just using "CONCAT".
– escbooster12
Mar 23 at 18:29
1
I am telling you how I would approach to that problem. Again, check two links I found on site for you and study it for a bit. You can't search something that doesn't exist. And temporary column doesn't exist. You should make/return one to have it for checking against comparing part. But what you can is to return only rows that comply to that case as I proposed you to do. You should try it with raw query first and after you have working query, only then try to convert to eloquent query builder.->where('full_address', 'LIKE', "%$searchAddress%")
won't work but try with raw query first.
– Tpojka
Mar 23 at 18:57
|
show 6 more comments
You have to combineCASE
. Check this answer to get an idea.
– Tpojka
Mar 23 at 16:00
When you say not working does the query fail or are you not getting data you're expecting and if it's the 2nd case can you share some data you'd expect to get but are not getting along with a query?
– apokryfos
Mar 23 at 16:06
@apokryfos already edited my question Sir. Could you mine to read it again, thanks Sir.
– escbooster12
Mar 23 at 18:26
@Tpojka thanks for reply Sir. Sir I'm not using "CASE WHEN", I'm just using "CONCAT".
– escbooster12
Mar 23 at 18:29
1
I am telling you how I would approach to that problem. Again, check two links I found on site for you and study it for a bit. You can't search something that doesn't exist. And temporary column doesn't exist. You should make/return one to have it for checking against comparing part. But what you can is to return only rows that comply to that case as I proposed you to do. You should try it with raw query first and after you have working query, only then try to convert to eloquent query builder.->where('full_address', 'LIKE', "%$searchAddress%")
won't work but try with raw query first.
– Tpojka
Mar 23 at 18:57
You have to combine
CASE
. Check this answer to get an idea.– Tpojka
Mar 23 at 16:00
You have to combine
CASE
. Check this answer to get an idea.– Tpojka
Mar 23 at 16:00
When you say not working does the query fail or are you not getting data you're expecting and if it's the 2nd case can you share some data you'd expect to get but are not getting along with a query?
– apokryfos
Mar 23 at 16:06
When you say not working does the query fail or are you not getting data you're expecting and if it's the 2nd case can you share some data you'd expect to get but are not getting along with a query?
– apokryfos
Mar 23 at 16:06
@apokryfos already edited my question Sir. Could you mine to read it again, thanks Sir.
– escbooster12
Mar 23 at 18:26
@apokryfos already edited my question Sir. Could you mine to read it again, thanks Sir.
– escbooster12
Mar 23 at 18:26
@Tpojka thanks for reply Sir. Sir I'm not using "CASE WHEN", I'm just using "CONCAT".
– escbooster12
Mar 23 at 18:29
@Tpojka thanks for reply Sir. Sir I'm not using "CASE WHEN", I'm just using "CONCAT".
– escbooster12
Mar 23 at 18:29
1
1
I am telling you how I would approach to that problem. Again, check two links I found on site for you and study it for a bit. You can't search something that doesn't exist. And temporary column doesn't exist. You should make/return one to have it for checking against comparing part. But what you can is to return only rows that comply to that case as I proposed you to do. You should try it with raw query first and after you have working query, only then try to convert to eloquent query builder.
->where('full_address', 'LIKE', "%$searchAddress%")
won't work but try with raw query first.– Tpojka
Mar 23 at 18:57
I am telling you how I would approach to that problem. Again, check two links I found on site for you and study it for a bit. You can't search something that doesn't exist. And temporary column doesn't exist. You should make/return one to have it for checking against comparing part. But what you can is to return only rows that comply to that case as I proposed you to do. You should try it with raw query first and after you have working query, only then try to convert to eloquent query builder.
->where('full_address', 'LIKE', "%$searchAddress%")
won't work but try with raw query first.– Tpojka
Mar 23 at 18:57
|
show 6 more comments
1 Answer
1
active
oldest
votes
Got the solution!!
I try different ways on how to "where" the raw column but no data returned, so I assume that these code->where('full_address', 'LIKE', "%$searchAddress%")
is I think syntax error.
We can't use "where clause" to raw columns such like "full_address".
So what I did is, I did not make a raw column such as "full_address" anymore, instead I directly "where" the DB::Raw
See my final and working codes:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country'
)
->where(DB::raw("CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)), 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
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%2f55315246%2fhow-can-i-where-raw-columndbraw-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Got the solution!!
I try different ways on how to "where" the raw column but no data returned, so I assume that these code->where('full_address', 'LIKE', "%$searchAddress%")
is I think syntax error.
We can't use "where clause" to raw columns such like "full_address".
So what I did is, I did not make a raw column such as "full_address" anymore, instead I directly "where" the DB::Raw
See my final and working codes:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country'
)
->where(DB::raw("CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)), 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
add a comment |
Got the solution!!
I try different ways on how to "where" the raw column but no data returned, so I assume that these code->where('full_address', 'LIKE', "%$searchAddress%")
is I think syntax error.
We can't use "where clause" to raw columns such like "full_address".
So what I did is, I did not make a raw column such as "full_address" anymore, instead I directly "where" the DB::Raw
See my final and working codes:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country'
)
->where(DB::raw("CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)), 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
add a comment |
Got the solution!!
I try different ways on how to "where" the raw column but no data returned, so I assume that these code->where('full_address', 'LIKE', "%$searchAddress%")
is I think syntax error.
We can't use "where clause" to raw columns such like "full_address".
So what I did is, I did not make a raw column such as "full_address" anymore, instead I directly "where" the DB::Raw
See my final and working codes:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country'
)
->where(DB::raw("CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)), 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
Got the solution!!
I try different ways on how to "where" the raw column but no data returned, so I assume that these code->where('full_address', 'LIKE', "%$searchAddress%")
is I think syntax error.
We can't use "where clause" to raw columns such like "full_address".
So what I did is, I did not make a raw column such as "full_address" anymore, instead I directly "where" the DB::Raw
See my final and working codes:
$searchAddress = $r->input('address'); //dynamic
$profile = DB::table('student')
->select(
'students.id',
'students.name',
'students.class',
'students.schedule',
'inf.streetNo',
'inf.city',
'inf.country'
)
->where(DB::raw("CONCAT(inf.streetNo,' ',inf.city,' ',inf.country)), 'LIKE', "%$searchAddress%")
->join('informations AS inf', 'inf.student_id', 'students.id')
->get();
edited Mar 24 at 9:29
answered Mar 24 at 9:23
escbooster12escbooster12
1669
1669
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%2f55315246%2fhow-can-i-where-raw-columndbraw-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
You have to combine
CASE
. Check this answer to get an idea.– Tpojka
Mar 23 at 16:00
When you say not working does the query fail or are you not getting data you're expecting and if it's the 2nd case can you share some data you'd expect to get but are not getting along with a query?
– apokryfos
Mar 23 at 16:06
@apokryfos already edited my question Sir. Could you mine to read it again, thanks Sir.
– escbooster12
Mar 23 at 18:26
@Tpojka thanks for reply Sir. Sir I'm not using "CASE WHEN", I'm just using "CONCAT".
– escbooster12
Mar 23 at 18:29
1
I am telling you how I would approach to that problem. Again, check two links I found on site for you and study it for a bit. You can't search something that doesn't exist. And temporary column doesn't exist. You should make/return one to have it for checking against comparing part. But what you can is to return only rows that comply to that case as I proposed you to do. You should try it with raw query first and after you have working query, only then try to convert to eloquent query builder.
->where('full_address', 'LIKE', "%$searchAddress%")
won't work but try with raw query first.– Tpojka
Mar 23 at 18:57