Search
 
SCRIPT & CODE EXAMPLE
 

PHP

concat in laravel 8


    $users = DB::table('users')->select("*", DB::raw("CONCAT(users.first_name,' ',users.last_name) AS full_name"))
        ->get();
Comment

concat using laravel

//must have
use IlluminateSupportFacadesDB;

Model::select(DB::Raw("CONCAT(profiles.first_name, ' ', profiles.last_name) AS name"))->get();

//concat other table data and display as one line with ',' as a delimiter
//DB::Raw("(SELECT GROUP_CONCAT(a.contact_number) FROM contacts as a JOIN users as b ON a.user_id = b.user_id WHERE a.user_id = users.user_id) AS contact")
//expected output would be 09123456789,09876543210,09000000000
Comment

how to use CONCAT in LARAVEL

public function scopeFindUserByName($query,$name) {
    // Concat the name columns and then apply search query on full name
    $query->where(DB::raw(
            // REPLACE will remove the double white space with single (As defined)
            "REPLACE(
                /* CONCAT will concat the columns with defined separator */
                CONCAT(
                    /* COALESCE operator will handle NUll values as defined value. */
                    COALESCE(name_first,''),' ',
                    COALESCE(name_middle,''),' ',
                    COALESCE(name_last,'')
                ),
            '  ',' ')"
        ),
    'like', '%' . $name . '%');
}
Comment

PREVIOUS NEXT
Code Example
Php :: object to string php 
Php :: laravel api csrf token disable 
Php :: get current year php 
Php :: convert number to 2 decimal places in php 
Php :: laravel model increase the value by one 
Php :: request old laravel form select 
Php :: php loop backwards through array 
Php :: google fonts change font in echo php 
Php :: php string to char array 
Php :: php convert special characters to unicode 
Php :: is php the fucking worst 
Php :: specified key was too long max key length is 767 bytes 
Php :: wp-admin redirecting to the https wordpress 
Php :: add new column in existing table in laravel migration 
Php :: php remove 1 day from date 
Php :: get first element of array php 
Php :: PHP | get client ip 
Php :: How to create an array from a CSV file using PHP 
Php :: set image asset path in laravel 
Php :: php sort array by key 
Php :: unset session in php 
Php :: twig ternary 
Php :: laravel validation max string length 
Php :: Get User IP address (PHP) 
Php :: current date time in php 
Php :: Invalid argument supplied for foreach() 
Php :: wp wordpress logout 
Php :: SELECT query with PDO 
Php :: php permanent redirect to url 
Php :: slug in php 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =