How to spilt Fullname to First name, middlename and lastname in Query Builder?SQL: parse the first, middle and last name from a fullname fieldSQL Server query - Selecting COUNT(*) with DISTINCTSQL Server: How to Join to first rowHow to query MongoDB with “like”?Get all table names of a particular database by SQL query?Get top 1 row of each groupHow to write a query to select a row comparing by spliting a fieldFirstname, middlename and lastname MS SQLSQL Server table first name last nameSplit name into multiple parts in SELECT statement
Is it a problem that pull requests are approved without any comments
Removing applications from Show Applications without uninstalling
Avoiding cliches when writing gods
Adding two lambda-functions in C++
What is the traditional way of earning a doctorate in Germany?
What makes linear regression with polynomial features curvy?
Why don’t airliners have temporary liveries?
Opposite of "Squeaky wheel gets the grease"
Reading two lines in piano
Company did not petition for visa in a timely manner. Is asking me to work from overseas, but wants me to take a paycut
How bad would a partial hash leak be, realistically?
Pros and cons of writing a book review?
Working in the USA for living expenses only; allowed on VWP?
How to skip replacing first occurrence of a character in each line?
Is it possible for people to live in the eye of a permanent hypercane?
What are the words for people who cause trouble believing they know better?
Do adult Russians normally hand-write Cyrillic as cursive or as block letters?
When writing an error prompt, should we end the sentence with a exclamation mark or a dot?
How do I calculate APR from monthly instalments?
How to make a setting relevant?
On the Twin Paradox Again
How could a government be implemented in a virtual reality?
Secure offsite backup, even in the case of hacker root access
What risks are there when you clear your cookies instead of logging off?
How to spilt Fullname to First name, middlename and lastname in Query Builder?
SQL: parse the first, middle and last name from a fullname fieldSQL Server query - Selecting COUNT(*) with DISTINCTSQL Server: How to Join to first rowHow to query MongoDB with “like”?Get all table names of a particular database by SQL query?Get top 1 row of each groupHow to write a query to select a row comparing by spliting a fieldFirstname, middlename and lastname MS SQLSQL Server table first name last nameSplit name into multiple parts in SELECT statement
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a table and there is a "name" field, but sometimes there are names that are too long, how do I just take the first name, middle name and last name (only 3 words)?
$student = DB::table('student')
->select('student.name')//Split to Firstname, Middlename&Lastname
->get();
sql laravel query-builder
add a comment |
I have a table and there is a "name" field, but sometimes there are names that are too long, how do I just take the first name, middle name and last name (only 3 words)?
$student = DB::table('student')
->select('student.name')//Split to Firstname, Middlename&Lastname
->get();
sql laravel query-builder
Please provide sample data, including data representing all edge cases (e.g. do some student names have only first and last, or maybe even just last). Without seeing your data, we can't give you an answer.
– Tim Biegeleisen
Mar 24 at 14:26
Perhaps, you can read about mutators It's a good way to do what you want do to.
– webmasterdro
Mar 24 at 14:49
add a comment |
I have a table and there is a "name" field, but sometimes there are names that are too long, how do I just take the first name, middle name and last name (only 3 words)?
$student = DB::table('student')
->select('student.name')//Split to Firstname, Middlename&Lastname
->get();
sql laravel query-builder
I have a table and there is a "name" field, but sometimes there are names that are too long, how do I just take the first name, middle name and last name (only 3 words)?
$student = DB::table('student')
->select('student.name')//Split to Firstname, Middlename&Lastname
->get();
sql laravel query-builder
sql laravel query-builder
edited Mar 24 at 14:28
Tim Biegeleisen
250k13104163
250k13104163
asked Mar 24 at 14:22
Khaiz Badaru TammamKhaiz Badaru Tammam
2318
2318
Please provide sample data, including data representing all edge cases (e.g. do some student names have only first and last, or maybe even just last). Without seeing your data, we can't give you an answer.
– Tim Biegeleisen
Mar 24 at 14:26
Perhaps, you can read about mutators It's a good way to do what you want do to.
– webmasterdro
Mar 24 at 14:49
add a comment |
Please provide sample data, including data representing all edge cases (e.g. do some student names have only first and last, or maybe even just last). Without seeing your data, we can't give you an answer.
– Tim Biegeleisen
Mar 24 at 14:26
Perhaps, you can read about mutators It's a good way to do what you want do to.
– webmasterdro
Mar 24 at 14:49
Please provide sample data, including data representing all edge cases (e.g. do some student names have only first and last, or maybe even just last). Without seeing your data, we can't give you an answer.
– Tim Biegeleisen
Mar 24 at 14:26
Please provide sample data, including data representing all edge cases (e.g. do some student names have only first and last, or maybe even just last). Without seeing your data, we can't give you an answer.
– Tim Biegeleisen
Mar 24 at 14:26
Perhaps, you can read about mutators It's a good way to do what you want do to.
– webmasterdro
Mar 24 at 14:49
Perhaps, you can read about mutators It's a good way to do what you want do to.
– webmasterdro
Mar 24 at 14:49
add a comment |
2 Answers
2
active
oldest
votes
I dont think eloquent can do this. You need to use php builtin functions
$fullname = explode(" ", $student);
$firstname = array_shift($split);
$lastname = implode(" ", $split);
add a comment |
Simpliest Way I think. Hope will help you
For me, it's a bad idea of splitting one word(fullname) into three, because what if, there are two words in his firstname, so the problem will exist as you are wishing only three words(first,middle,&lastname).
But if you really want to pursue, here's the code for that:
$student = DB::table('student')
->select(
'student.name',
DB::raw("SUBSTRING_INDEX(student.name, ' ', 1) AS Firstname"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 2),' ',-1) AS Middlename"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 3),' ',-1) AS Lastname")
)
->get();
I assume you use or it is space(' ') that joins three words (first,middle, & last name)
Note examples outputs:
1. John Ghost Pon
Firstname = "John", Middlename = "Ghost", Lastname = "Pon"
2. Marry Anne Smith Ingram
Firstname = "Marry", Middlename = "Anne", Lastname = "Smith"
SUBSTRING_INDEX Function returns a substring of a string before a specified number of delimiter occurs: More examples
Please let me know if still doesn't work.
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%2f55324779%2fhow-to-spilt-fullname-to-first-name-middlename-and-lastname-in-query-builder%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I dont think eloquent can do this. You need to use php builtin functions
$fullname = explode(" ", $student);
$firstname = array_shift($split);
$lastname = implode(" ", $split);
add a comment |
I dont think eloquent can do this. You need to use php builtin functions
$fullname = explode(" ", $student);
$firstname = array_shift($split);
$lastname = implode(" ", $split);
add a comment |
I dont think eloquent can do this. You need to use php builtin functions
$fullname = explode(" ", $student);
$firstname = array_shift($split);
$lastname = implode(" ", $split);
I dont think eloquent can do this. You need to use php builtin functions
$fullname = explode(" ", $student);
$firstname = array_shift($split);
$lastname = implode(" ", $split);
answered Mar 24 at 14:50
rameez.hashmirameez.hashmi
129
129
add a comment |
add a comment |
Simpliest Way I think. Hope will help you
For me, it's a bad idea of splitting one word(fullname) into three, because what if, there are two words in his firstname, so the problem will exist as you are wishing only three words(first,middle,&lastname).
But if you really want to pursue, here's the code for that:
$student = DB::table('student')
->select(
'student.name',
DB::raw("SUBSTRING_INDEX(student.name, ' ', 1) AS Firstname"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 2),' ',-1) AS Middlename"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 3),' ',-1) AS Lastname")
)
->get();
I assume you use or it is space(' ') that joins three words (first,middle, & last name)
Note examples outputs:
1. John Ghost Pon
Firstname = "John", Middlename = "Ghost", Lastname = "Pon"
2. Marry Anne Smith Ingram
Firstname = "Marry", Middlename = "Anne", Lastname = "Smith"
SUBSTRING_INDEX Function returns a substring of a string before a specified number of delimiter occurs: More examples
Please let me know if still doesn't work.
add a comment |
Simpliest Way I think. Hope will help you
For me, it's a bad idea of splitting one word(fullname) into three, because what if, there are two words in his firstname, so the problem will exist as you are wishing only three words(first,middle,&lastname).
But if you really want to pursue, here's the code for that:
$student = DB::table('student')
->select(
'student.name',
DB::raw("SUBSTRING_INDEX(student.name, ' ', 1) AS Firstname"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 2),' ',-1) AS Middlename"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 3),' ',-1) AS Lastname")
)
->get();
I assume you use or it is space(' ') that joins three words (first,middle, & last name)
Note examples outputs:
1. John Ghost Pon
Firstname = "John", Middlename = "Ghost", Lastname = "Pon"
2. Marry Anne Smith Ingram
Firstname = "Marry", Middlename = "Anne", Lastname = "Smith"
SUBSTRING_INDEX Function returns a substring of a string before a specified number of delimiter occurs: More examples
Please let me know if still doesn't work.
add a comment |
Simpliest Way I think. Hope will help you
For me, it's a bad idea of splitting one word(fullname) into three, because what if, there are two words in his firstname, so the problem will exist as you are wishing only three words(first,middle,&lastname).
But if you really want to pursue, here's the code for that:
$student = DB::table('student')
->select(
'student.name',
DB::raw("SUBSTRING_INDEX(student.name, ' ', 1) AS Firstname"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 2),' ',-1) AS Middlename"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 3),' ',-1) AS Lastname")
)
->get();
I assume you use or it is space(' ') that joins three words (first,middle, & last name)
Note examples outputs:
1. John Ghost Pon
Firstname = "John", Middlename = "Ghost", Lastname = "Pon"
2. Marry Anne Smith Ingram
Firstname = "Marry", Middlename = "Anne", Lastname = "Smith"
SUBSTRING_INDEX Function returns a substring of a string before a specified number of delimiter occurs: More examples
Please let me know if still doesn't work.
Simpliest Way I think. Hope will help you
For me, it's a bad idea of splitting one word(fullname) into three, because what if, there are two words in his firstname, so the problem will exist as you are wishing only three words(first,middle,&lastname).
But if you really want to pursue, here's the code for that:
$student = DB::table('student')
->select(
'student.name',
DB::raw("SUBSTRING_INDEX(student.name, ' ', 1) AS Firstname"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 2),' ',-1) AS Middlename"),
DB::raw("SUBSTRING_INDEX(SUBSTRING_INDEX(student.name, ' ', 3),' ',-1) AS Lastname")
)
->get();
I assume you use or it is space(' ') that joins three words (first,middle, & last name)
Note examples outputs:
1. John Ghost Pon
Firstname = "John", Middlename = "Ghost", Lastname = "Pon"
2. Marry Anne Smith Ingram
Firstname = "Marry", Middlename = "Anne", Lastname = "Smith"
SUBSTRING_INDEX Function returns a substring of a string before a specified number of delimiter occurs: More examples
Please let me know if still doesn't work.
edited Mar 24 at 19:07
answered Mar 24 at 19:02
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%2f55324779%2fhow-to-spilt-fullname-to-first-name-middlename-and-lastname-in-query-builder%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
Please provide sample data, including data representing all edge cases (e.g. do some student names have only first and last, or maybe even just last). Without seeing your data, we can't give you an answer.
– Tim Biegeleisen
Mar 24 at 14:26
Perhaps, you can read about mutators It's a good way to do what you want do to.
– webmasterdro
Mar 24 at 14:49