Posted inTechnology / Laravel / Mysql / Mysqli / php / Programming

Laravel 6 CONCAT Multiple Columns with example

Today, We want to share with you Laravel 6 CONCAT Multiple Columns with example.In this post we will show you CONCAT columns with Laravel 6 eloquent, hear for CONCAT Two Columns in Laravel with Example we will give you demo and example for implement.In this post, we will learn about laravel eloquent where concat with an example.

Laravel 6 CONCAT Multiple Columns with example

There are the Following The simple About laravel concatenate string in controller Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel concat two columns with example, so the concat two columns in laravel 6.2 query is used for this example is following below.

Example 1 : Laravel Wrap Query in DB::raw

query in DB::raw.

public function members()
{
    $members = DB::table('members')->select("*", DB::raw("CONCAT(members.first_name,' ',members.last_name) AS full_name"))
        ->get();

    foreach ($members as $member) {
         echo $member->full_name . '
'; } }

Example 2 : Using Pluck Method

use the pluck() method to concat two columns

public function members()
{
    $members = DB::table('members')->select('id', DB::raw("CONCAT(members.first_name,' ',members.last_name) AS full_name"))->get()->pluck('full_name', 'id');
    dd($members);
}

Example 3 : Define Custom Method in Model

app/Member.php

protected $fillable = [
    'first_name', 'last_name', 'email', 'password',
];

public function getFullNameAttribute()
{
    return "{$this->first_name} {$this->last_name}";
}

run the query and get full name

public function members()
{
    $members = Member::get();

    foreach ($members as $member) {
         echo $member->full_name . '
'; } }
Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about concat in laravel 6.2 blade.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype