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 :: php loop in js 
Php :: php class 
Php :: php typecast class 
Php :: laravel stack script 
Php :: which is file attributes in php 
Php :: Laravel all() and get() 
Php :: Spatie vendor publish 
Php :: wordpress access database php 
Php :: creating jobs laravel 
Php :: if certain condition is met exit if block php 
Php :: enable phpmailer cpanel 
Php :: laravel request not returning errors 
Php :: php return multiple variables from function 
Php :: how to split sting in php 
Php :: create seed file from db laravel 
Php :: Laravel storage:link not working 
Php :: laravel eloquent relationships 
Php :: codeigniter crud generator 
Php :: php array lenght 
Php :: laravel collection all 
Php :: laravel default rate limit 
Php :: iterator 
Php :: Symfony Expected argument of type "string", "null" given 
Php :: Change the colorbar scale to log scale 
Php :: PHP metaphone — Calculate the metaphone key of a string 
Php :: replace special characters from string in codeigniter 
Php :: where post_type like 
Php :: echo two variables same line php 
Php :: ob_start store variable in php 
Php :: Crear un componente livewire 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =