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;








0















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();









share|improve this question
























  • 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

















0















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();









share|improve this question
























  • 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













0












0








0








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();









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












2 Answers
2






active

oldest

votes


















0














I dont think eloquent can do this. You need to use php builtin functions



$fullname = explode(" ", $student);
$firstname = array_shift($split);
$lastname = implode(" ", $split);





share|improve this answer






























    0














    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.




    share|improve this answer

























      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
      );



      );













      draft saved

      draft discarded


















      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









      0














      I dont think eloquent can do this. You need to use php builtin functions



      $fullname = explode(" ", $student);
      $firstname = array_shift($split);
      $lastname = implode(" ", $split);





      share|improve this answer



























        0














        I dont think eloquent can do this. You need to use php builtin functions



        $fullname = explode(" ", $student);
        $firstname = array_shift($split);
        $lastname = implode(" ", $split);





        share|improve this answer

























          0












          0








          0







          I dont think eloquent can do this. You need to use php builtin functions



          $fullname = explode(" ", $student);
          $firstname = array_shift($split);
          $lastname = implode(" ", $split);





          share|improve this answer













          I dont think eloquent can do this. You need to use php builtin functions



          $fullname = explode(" ", $student);
          $firstname = array_shift($split);
          $lastname = implode(" ", $split);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 14:50









          rameez.hashmirameez.hashmi

          129




          129























              0














              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.




              share|improve this answer





























                0














                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.




                share|improve this answer



























                  0












                  0








                  0







                  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.




                  share|improve this answer















                  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.





                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 24 at 19:07

























                  answered Mar 24 at 19:02









                  escbooster12escbooster12

                  1669




                  1669



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                      155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해